I have a huge XAML theme with multiple control templates and styles. I need to find out which styles from this list are being applied to which of my controls. I see that the style of my control has changed, but I can't find the source template/style for that change. For example, I have a Grid and I see that the background has changed, but I can't find the the templates/styles that have that Grid as its TargetType with any of that Grid's parameters.
Use the Snoop tool that can show you all your layout hierarchy and if element's attribute was set locally or inherited.
Related
Just wondering if there is any tool to see what Style is setting a property value for a control. In our application, all the RadComboBoxes have IsEditable property set to true. There is some DLL that we are using is causing this. I am guessing there is some Style without a Keyfor the RadComboBox that sets this.
In WPF Inspector, I can see that every RadComboBox control in our App has IsEditable set to True. And under the Resources section there are a bunch of resources that show up, and some of these are set inside some external DLLs that we include in our project.
I would like to know what particular Style is causing this, so that we can narrow down our problem.
I usually check who set the property on Telerik controls by using Snoop.
Pin the element with Control + Mouse hover. Then select exact element in visual tree, select the suspecting Style property and use Delve button to see properties of Style property, namely look for x:Key.
When you find the key (usually RadSometingStyle or Template), open the install directory of Telerik controls, browse to Themes foleder and search over the all xaml files there. You'll find the style definition there. Good luck... :)
How can i add different items with either background/foreground color different in WPF listbox?
You can can create a DataTemplete, set it to ListBox.ItemTemplate and use DataTrigger to change the display of the items.
ListBox has some very annoying behaviors that make styling it using data template difficult - in this blog post you will find the list of workarounds.
You may use an AlternationCount property, more info provided by this link
Or you can add to your objs binded to a listbox Background and Foreground properties and bind them in a DataTemplate of ListBox.ItemTemplate and change them in code however you like, properties must update themselves on every changing.
After tearing my hair out with this one (and your particular usecase might differ from mine) I found the WPF Toolkit's DataGrid cured all my needs.
I'd like to know what the differences between an Style (for a control) and a control template are.
Best regards,
Gonzalo
A style controls the individual properties of a control. For instance, a button style can say, "For every button, use this background." A style is changing a single property on a control.
A control template is actually handling how the control displays its bound data. Instead of saying, "I want to override a control's properties," you are assembling together other smaller controls into a single control that can present different views of the bound data.
Previously in WinForms, if you wanted to write a custom list box (say that had an icon next to each item), you had to inherit from the ListView control and override the painting methods. This involved a ton of experimentation - huge pain. With WPF templates, you can use XAML to construct smaller controls together and bind them to different properties of the parent control. You are actually defining the Visual Tree for the control.
See this article for an in-depth explanation by Charles Petzold.
Imagine your control is a house.
A Style is conceptually similar to putting down a new carpet and painting the walls. The house itself is still the same but its outward appearance is different.
A ControlTemplate is the equivalent of knocking down a wall or adding a conservatory. The actual structure of the house has changed.
Use a Style when you want to change the outward appearance of the control E.G. it's background colour or the thickness of it's border.
Use a ControlTemplate when you need to change the underlying structure of the control. This is useful when you want to change the layout of certain aspects of a control. A good example is in this article which re-templates a TabControl to look like the navigator from Microsoft Outlook.
i am looking to extend a third party control, it is a ComboBox (so it isn't the standard Silverlight one, but that shouldn't matter for this question). To do this, i add a new template control to my controls project, then i change the new control to inherit from ComboBox instead of Control. A style has been created for me in the generic.xaml file, so i delete the default border stuff that was inserted, and then add a property setter for the PopupTemplate.
My problem is that when doing it this way, the combobox doesn't (visibly) render in the silverlight application anymore. However, in the constructor of my extension if i comment out the line
this.DefaultStyleKey = typeof(MyComboBox);
and put the PopupTemplate xaml bit in the main silverlight page, it renders correctly. I want the popup template to be declared within the control library, but does this mean that i also have to define the regular Template property? Am i wrong in thinking that anything i don't explicitly specify should just be inherited from the base control?
A control can only have one default style. You need to copy the entire default style of the base control into the Generic.Xaml for you new MyComboBox then adjust it accordingly.
I'm interested in customizing a 3rd party control, such as Telerik's RadGridView, as a standalone control, for example adding New Row and Delete Row buttons above the grid, yet still supporting XAML manipulation of the internals of the control by the window upon which my control exists (i.e. for the window to add its own style to a column of the grid).
Is there a way to add the buttons, etc. with templates? Styles?
My current "solution" is to inherit from the RadGridView, but I'm stuck on how to add the features I need.
Thanks!
My suggestion is to use composition over inheritance.
You can create your own control (UserControl should do the work). Then you can define the layout (may be in Grid panel): buttons on the top, RadGridView bellow them, etc. For custom column styling you can use DynamicResource trick. Set the styles of the columns you want to modified with DynamicResource. This way when the control is added to the logical(visual) tree; WPF will walk up the control tree and find appropriate resource. This way in each window/page resources you can define the different resource.
Another idea that come to my mind is that you can extract the buttons as a separate control. The only reference that they will need will be RadGridView and you can use binding with element name to provide it.
I would go the custom UserControl route instead of inheritance route. Styling and theming work strangely when you're dealing w/sub-classes. Unless you're planning on duplicating and modifying Telerik's ControlTemplates and DataTemplates, it can get pretty hairy.