Use parts of default WPF controls for binding - wpf

Is it possible to use the parts of default WPF controls for binding?
Specifically, I'm aiming at binding the padding size of a ListBox control to the width of the arrow part of a ComboBox control.
Using VS 2015 Live Visual Tree, I can see that the specific part I'm interested in is named 'splitBorder', which is the portion of the ComboBoxToggleButton that contains the downwards arrow symbol.

Specifically, I'm aiming at binding the padding size of a ListBox control to the width of the arrow part of a ComboBox control.
No, you can't really do this since the width of the arrow and the arrow itself is hardcoded within the ControlTemplate of a ToggleButton that is part of the default ControlTemplate of the ComboBox.
You cannot bind to the arrow Path from any element outside of the control template where it is defined and the ComboBox class doesn't expose the arrow from any public property that the ListBox can bind to. So this is not possible I am afraid.

Related

WPF Toolkit autocompletebox itemtemplate

I'm following this reference to implement an autocomplete textbox in my application:
http://www.broculos.net/2014/04/wpf-autocompletebox-autocomplete-text.html
I notice there is a difference when using an itemtemplate vs not using one. When using a template the items have more space between them. I need to use the itemtemplate but how can I make it look more like when not using a template, move the items closer to each other?
When not using an ItemTemplate, the single items in the dropdown list will be simple strings and will be represented by TextBlocks in the UI. TextBlocks don't have any margin by default, so the lines are close together.
Assigning an ItemTemplate will replace this visual appearance (with whatever the ItemTemplate defines). Most probably there is some margin/padding defined in the ItemTemplate, e.g. if an Label is used as representation (Labels have some default margin assigned).
Changing the margin/padding properties of the single elements of your ItemTemplate should help here.

why did the arrows in my treeview turn to strange squares

I have an user control which has a treeview. This user control inherits from a base user control.
I was able to see the arrows in the treeview well till I changed the base control graphics.
From that point I started to see strange squares instead of the regular arrow in the treeview.
Is there any reason for this behavior?
This behavior was influenced by a style that was defined in the app.xaml.
The target type of the style was Border.
Probably the type of the arrows in the treeview is some border, and the public border type in the app xaml caused those arrows to be changed.

Overriding the view of a DataGrid scrollbar

I am trying to customize the look of a scrollbar inside a xaml datagrid. I can create the usercontrol for the style with no problems, but if I wrap it around the datagrid that doesnt work. Is there something I can bind to within the DataGrid properties that would use the custom control or style?
Thanks SO
First, you need to make your custom ScrollBar control template. Then you can open a copy of the DataGrid control template in Expression Blend, find the existing scrollbar control it's using and apply your style to it then save it in a resourced dictionary using the BasedOn value to the TargetType. This is recommended or if its an adhoc solution, you can apply it to the usercontrol.resources of your datagrid.
You can find the scrollbar control template here

Style a WPF Expander to look like an Outlook ListView group header

How can you style a WPF Expander image to be +/- e.g. to look like an Outlook ListView group header as shown in the image below:
Open
Closed
Not exactly but close enough, check out this article by Karl Shifflet on WPF Sample Series – ListBox Grouping, Sorting, Subtotals and Collapsible Regions from the WPF LOB Tour Materials
(source: wordpress.com)
You would have to override the Expander's ControlTemplate, and change the ContentControl with the TemplateBinding of Header (this is usually a ToggleButton) with your header content.
In your case this is the +/- image/geometry and text.
However, I would go a different route than using an Expander. Since you're using a very specific orientation, I would just borrow the ToggleButton+ContentControl interaction that the default Expander ContentControl combines, and create a new Style/ControlTemplate for the ToggleButton instead.
The primary reason why I recommend this instead of overriding the ControlTemplate of the Expander is that Expander has a very large default ControlTemplate definition, and you won't have to deal with overriding all of the ExpandDirection options.
Alternately, you could just ignore the ExpandDirection property of the Expander and remove the ControlTemplate trigger code and associated Styles which deal with that.

ItemTemplate vs ControlTemplate

I am confused with learning about WPF. I see ControlTemplate used to determine how each item in a listbox looks. Isn't that what the ItemTemplate is used for in listboxes? What is the difference?
A ControlTemplate let's you change the look&feel of existing controls, for example, make a normal everyday button look like Vista's taskbar shiny glass buttons or make a tab control look like the new Office 2007 ribbon.
The idea is that the control contains only the behavior and the ControlTemplate contains the look&feel - so a button is "something you click" not "a rectangle with some 3d effect you can click on".
You can replace the ListBox's control template to get something like a list box with rounded corners or custom scroll bars.
A DataTemplate (ItemTemplate is a property of type DataTemplate) on the other hand let's you control how the data rows displayed inside list boxes (and other similar controls), data templates are used to specify things like "Show last name, than a comma and the first name - and the last name should be bold and the first name should be green if it starts with an A".
And just for completeness there is also an ItemsPanelTemplate class that is used to change the internal layout of a list box - Charles Petzold's WPF book has an example of using it to make a normal list box display it's items in a circle.
An ItemTemplate describes how to render the data item in a listbox (for example, you might have your listbox bound to a List - the ItemTemplate will allow you to specify how to render a Foo). An ItemTemplate is a DataTemplate.
A ControlTemplate describes how the ListBox itself should be rendered

Resources