Get TreeView's styled expand/collapse icons - wpf

I need to render/draw the icons that the default TreeView uses for it's expand/collapse icons. I already found out that you can change them by writing a new style with x:Key="ExpandCollapseToggleStyle", but I have no idea how I could load that style from the currently loaded theme (e.g. Aero, Luna, etc.).
I already tried creating a ToggleButton and applying it's Style the StaticResource ExpandCollapseToggleStyle, but the resource can not be found:
<ToggleButton Style="{StaticResource ExpandCollapseToggleStyle}"></ToggleButton>
How can I apply styles defined in the default theme to controls they are not actually meant for?

it doesn't really work that way.
you have to extract the styles from that specific theme, copy them to your code and then reference them. Look here for how to extract the styles and templates. Martin Liversage's answer number 2 doesn't only work on silverlight assemblies. You can use Reflector (too bad it's commercial now...) to get the styles and themes from wpf dlls too.
btw: the corresponding ddls are named like PresentationFramework.Luna.dll

Related

How to get WPF default Styles and ControlTemplates for DataGrid and sub controls?

I need to make several changes to the default Styles and ControlTemplates of all major UserControls of my application. I found this very easy to do for allmost all UserControls (RightClick control in VS2015 designer => Edit template => Edit a copy...) and maybe a little bit more complicated for the more complex ones like the Calendar, but I totally fail for DataGrid and its now sub controls.
While it is of course easy to get the style and template for the DataGrid itself I still need the styles for DataGridRow, DataGridRowHeader, DataGridColumnHeader, DataGridCell, ... I do not even know all possible sub elements.
I searched the internet for about half a day now and could not find any solution to my issue:
If I check the MSDN for default styles of the DataGrid it gives me a bad example that contains weird stuff like FrozenGridDataGrid and other stuff that is not contained in the referenced Namespaces and assemblies. I'm not sure if this example is targeted towards Silverlight only...
Tools like 'Show Me The Templates!' do not list the DataGrid...
The BAML Viewer addin for .Net Reflector does only show me my custom styles but not the default ones. Targeting for example the PresentationFramework.Aero.dll does not work.
I even found an example by Jamie Rodriguez on the MSDN on how to style the DataGrid which gets very close to what I need - but then again I do not know how close his code is to the defaults, if something is missing and also his result looks like a color palette...
Can anyone please tell me what styles and templates I need to cover the whole DataGrid and where I can get their defaults?
Thanks
Use Blend.
You will get all templates.

Silverlight: Style for Custom Control in Same Project

I have a Silverlight application with a custom control MyDataGrid which is a DataGrid with some extra features.
This is part of the project in which it is used. It also requires a custom style. I can add the style to my style resource dictionary and set TargetType="sdk:DataGrid" which works.
However, my style relies on a property MyProperty specific to MyDataGrid, so a warning appears in the editor. More importantly, the styles cannot be previewed in the designer.
They DO work when the code is run, however.
My question is: Is there a way to pull in local controls to a resource dictionary, rather than creating a separate project, compiling it to a .dll, and pulling in that assembly?
Thanks!
It sounds like you made a custom control, but you haven't defined a default style for it. Try the following:
In your project, add a folder at the root level called Themes.
In the Themes folder, add a ResourceDictionary named generic.xaml.
Add all of your MyDataGrid styles to generic.xaml.
Make sure one of the styles is an implicit style (using BasedOn is a great solution here).
In the default constructor for MyDataGrid, add the line DefaultStyleKey = typeof(MyDataGrid);
If you want to access part of the style (which is defined in XAML) from code, you should name that XAML item as "PART_something". The design tools understand the PART_* syntax plus that's an indication to library consumers that if you retemplate the control, you must define the required pieces prefixed with PART_.
Here are the basics on how to define a custom control.

Is there a way to quickly create a style from a set of selected attributes?

I currently want to create a wpf style by selecting a group of attributes, e.g. Height, Width of a button, then right click and call a command like "Generate style from selection" and the IDE will do the rest for me: add .Resource tags, and a Style with sample x:Key and put the attributes' names and values into Setter tags.
Is it possible? Any addons are welcome. I prefer to have a free solution. Please discuss!
If you have Expression Blend at your disposal, creating a new style is fairly simple. Just a matter of stubbing out the style in code
<Style x:Name="MyStyle" TargetType="{x:Type TextBlock}"/>
Open the Resource browser, select the style you just made, and then use the properties box to set the properties.
As for Visual Studio, I have not yet seen a WPF extension that would do it even this automated. The XAML designer in Visual Studio leaves a lot to be desired for me, and one of the reasons is the style creation.
Blend has style visualization, VS2010 does not. Any styling stuff that I do, is in Blend.

Encapsulating and customizing a third party WPF control

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.

How do I set the theme for child controls with Infragistics?

I'm using the Infragistics WPF controls in a new project, and I'd like to take advantage of their themes support. I'm able to change the theme of my window (and toolbars) via the OnThemeChanged event, but I can't figure out how to change the theme of child controls (such as the XamDockManager), as they're added at runtime.
I'm new to WPF and Infragistics controls so any clarification is appreciated.
I discovered the answer.
You need to set the control's Theme property to Theme.CurrentTheme. This will cause the controls to automatically pick up the new theme via their internal OnThemeChanged events.
This is the code I used, simplified a bit for this answer:
<igDock:ContentPane xmlns:igTheme="clr-namespace:Infragistics.Windows.Themes;assembly=Infragistics3.Wpf.v9.1">
// other stuff
...
<igDock:XamDockManager "Theme="igTheme:ThemeManager.CurrentTheme" />
</igDock:ContentPane>

Resources