How to set the width of the scrollbar inside a ScrollViewer in UWP? - xaml

I have a ComboBox with thousands of items bound to it.
The problem I'm facing is when I run the app on a tablet the scrollviewer's scrollbar is very thin hence I cannot hold and drag it and can only swipe to move inside the ComboBox.
Hence I was wondering is there a way to change the style template of the ScrollViewer inside the ComboBox inorder to make the ScrollBar width larger.

You'll have to dig in to the style template and change some hard set properties for Width / Height that sit on the parts like the Thumb that you will find on the default style template. You can extract a copy via selecting a Scrollbar -> Right Click -> Edit Style -> Edit a copy. Save the copy wherever you need it, like a resource dictionary if you plan to use it multiple places or to the instance where you need it.
(Note: Generally folks start at the ScrollViewer level, then find a Scrollbar in it, and apply the style changes there so they can apply the style directly to ScrollViewers)
Once you have your changes made to the control template you then need to pass them to your ComboBox. If you only need it for the one ComboBox, You can just put the style template in it's Resources and remove the x:Key name you gave it so it hits the instance of the TargetType via inheritance for just that ComboBox.
However if you want it to hit EVERY ComboBox, then you'll need to edit the ComboBox style template and add a reference to the Style template you just made to it's embedded ScrollViewer.
You'll find long tutorials out there for stuff like WPF/Silverlight that pretty much the same concept but little nuance differences in the templates and syntax of properties.
Hope this helps, give it a shot and if you get stuck come on back and we'll get you sorted.

Related

Determine Source of XAML Styling

I have a couple of ListViews on different pages in my UWP application. For some reason, one of them seems to have Padding along the bottom below the last ListViewItem, while the other does not.
Neither of them has bottom Padding specified, so I'm wondering if this could be inherited from a parent control? I searched the entire XAML of the one with Padding, and it is not set anywhere else either. It isn't a huge problem, but I would prefer my controls to be consistent throughout my application, and I think adding the bottom Padding to the ListView without it to make them match seems silly, especially when I am unsure of why the first one has Padding in the first place.
Is there somewhere to determine where properties are set in the hierarchy, similar to the way CSS works?
Here is what they look like:
No padding:
Padding:
I added a Background to the ListView control to verify that there is no Padding there..
So it would seem it would have to come from the ListViewItem itself, but it does not have the Padding property set.
The issue turned out to be that one of the parent controls of the ListView that was displaying correctly (how I wanted it to) had a VerticalAlignment="Top" set, while all the parents of the other ListView were set to VerticalAlignment="Stretch".
I was finally able to get XAML Spy working properly, and it was helpful in previewing the changes while the application was running so that I could determine which element I needed to set the VerticalAlignment on without recompiling over and over again. Thanks to #ChrisW for the recommendation.

What technique will I use if i want to change this panel when I click a button in VB

I just have it in my mind. And I can't explain it so here it goes.
A system that only uses 1 form?
It have a two panel, left and right.
The left is consist of buttons
Then the right is associated on the buttons and will change whether what button will be clicked.
Any ideas?
My preference is to do this via custom controls, rather than panels... but panels can work too.
There are a number of ways to do this:
Keep all of the controls layered on top of each other, and then set the Visible property to false for controls/panels you don't care about and to true for the Control/Panel that you do
Move the controls you don't care about out of the visible area
Remove/Add the Controls/Panels from Form's controls collection entirely
I think you can also get a TabControl to put the tabs along the left side, with some formatting that looks more like buttons, such that what you want will be handled without needing to write any code to switch layouts
Any of those can work. Whichever option you use, I have two recommendation for controlling layout and making the transitions smooth.
Call SuspendLayout() before making any changes, and then call ResumeLayout() when you're done. This will help avoid stuttering or a partially rendered form.
Look at the TableLayoutPanel Control. This control will allow you to arrange your top-level panels so that they can be resized with proportion. If you also then dock your individual panels, you can quickly build your program so that it resizes correctly.
You can have several panels, one on top of another. Change their visibility, depending on which one you need at a given moment.
Option #2 would be using a vertical tab control (or a tab strip - see another answer there).

Custom button in Windows 8.1 app

I have a requirement to create a button in a Windows 8.1 app which has an icon and a text label. The icon will be a symbol from Segoe UI Symbols and the text label will be Segoe UI Semibold at a smaller text size.
I want to be able to reuse the button in different places within the app, using different icons and text labels.
How show I go about this? I could create a button and then edit the ContentPresenter to have a horizontally oriented stack panel with two TextBlocks, but then how could I reuse this? And how could I change the text in the two different text blocks?
Should I create a separate custom control with separate dependency properties for each of the textblock strings? I'm interested in hearing what you would do.
thanks
Create a simple Style. To make it easy, I would base it off the standardized AppBarButton style. You can format it to whatever size you want (I have done something similar to make a larger button or one with text on the side).
Have the main icon simply be a ContentPresenter which binds to the Content using a TemplateBinding. Make sure to set the FontFamily to Segoe UI Symbol. Have the text label pull from AutomationProperties.Name, similar to how the AppBarButton style does.
Then, whenever you want to use this just do:
<Button Style="{StaticResource MyCustomButtonStyle}"
Content="" // Where "000" is replaced by the number of the icon you wish to use.
AutomationProperties.Name="Text Label"/>
This should be extensible and easily reproducible to whatever location you need. When copying over the AppBarButton style, I suggest removing the artificial size limits (specifically the width of the main content Grid). I do suggest either giving the Text Label a fixed size or having it pull its size from the specified parent Width, so that it will Wrap correctly.
Hope this helps and happy coding!
Are you desiring to create something like for an AppBar? Take a look at AppBarButton and the style/types it supports. In Windows 8.1 we added some things around SymbolIcon specifically. Since you basically want two pieces of 'content' for your style you'll have to re-purpose one property (unless you create a custom control which doesn't sound needed for this scenario). Using AutiomationProperties.Name for the visible label is a good idea because it will also help with accessibility by default for those users.
Investigate the style for AppBarButton to get you started.

WP8 PhoneAccentBrush doesn't affect TextBox focus border

I'm trying to make my WP7 app work well on WP8 (by compiling it as a WP8 app).
In my app, I'm changing the PhoneAccentBrush's Color which seems to work fine still, however TextBox's in WP8 now seem to show a border around it when the textbox is in focus (this wasn't happening for me on WP7). This border seems to always use the System's accent color instead of using the changed color like every other control.
Any idea what's going on here and how to change it? The red accent (if that's what the user has chosen) really clashes with my app's colors!
I would call overriding the accent color a hack. I would avoid setting the accent color and create a template for your textBlock.
Blend makes this very easy by allowing you to copy the default template and make changes to it.
Right Click the textBox in the Objects and Timeline pane, then select Edit Template -> Edit Current. Then select the States tab and select the Focused FocusState, then edit the border brush. Save and reuse the template as needed.
I did notice the textBox control template has changed in 8 and now defines the focus state border brush, although it does default to the PhoneAccentBrush.

FlowLayoutPanel not showing all contents?

Very weird situation going on with a FlowLayoutPanel...
I have been dynamically adding user controls to my panel. This user control has a height of 105. If I have my FlowLayoutPanelwidth to only show 1 "column" of controls, it will only display 296 of them. The rest of the controls are grayed out at the bottom of the flowlayoutpanel. If I widen the flp to allow 2 "columns" of controls, I can see 592 of them, with the remainder grayed out at the bottom. I have gone in and resized the user control to make it shorter in height, which works in some respects (i.e. it works when I have two columns, but not just 1), and can go forward with this work-around.
So, I guess my question is, why does the FlowLayoutPanel behave in this fashion? It seems (based on what I saw) that there is a limit to how much data the FLP will show at one time.
Your comment just reminded me that when you're adding many controls to any container it is a good idea to do this:
YourPanel.SuspendLayout();
// populate panel with controls
YourPanel.ResumeLayout(false);
This in effect stops the container (panel) from re-rendering itself every time you add a control until you're done adding controls. In the very least your panel creation will be smoother and faster. Not sure if this might fix your issue or avoid the need for a hack with PerformLayout.
If you look at your Form's designer file you will actually see this in action in the InitializeComponent function.