I have described my problems with binding the SelectedItem of the RibbonComboBox. Another very ugly issue arises when trying to style this control.
Starting with the unstyled ComboBox from the post mentioned above:
<r:RibbonComboBox >
<r:RibbonGallery SelectedItem="{Binding SelectedItem, Mode=TwoWay}">
<r:RibbonGalleryCategory ItemsSource="{Binding Controls}" DisplayMemberPath="Caption" />
</r:RibbonGallery>
</r:RibbonComboBox>
I get the expected result:
But when applying a style with the help of Microsoft Blend (Preview for VS 2012), Object | Edit Style | Edit a Copy... (copying only the Template, with Blend or Visual Studio, has the same effect):
The selected item will no longer be displayed correctly - instead of the DisplayMemberPath property, the type name is shown. Items in the dropdown are still correct. Note that I did not yet change the style in any way, it is the default style/template that gets extracted that will produce this issue.
<r:RibbonComboBox Style="{DynamicResource RibbonComboBoxStyle1}" >
I also had trouble to style my dropdown items (mainly wanted to change the mouseover background cornerradius), because the ItemContainerStyle for the RibbonComboBox will have target type RibbonMenuItem and does not seem to have an effect on the actual RibbonGalleryItems.
How to fix the RibbonComboBox style?
How can I get to the RibbonGalleryItem style by way of Blend/VS?
Currently, I have solved this issue by extracting the default RibbonComboBox style directly from RibbonControlsLibrary.dll (Resources/RibbonControlsLibrary.g.resources/themes/generic.baml) with ILSpy.
This is tedious work, because the style references other StaticResources in the same file, so you need to find and extract those, too.
The same applies to the RibbonGalleryItem style, it can be extracted like this, but I would prefer a "cleaner" solution involving Blend or Visual Studio.
You may want to take a look at JetBrains dotPeek decompiler.
One of its features is:
"... decompile .baml files, enabling you to reconstruct XAML UI definitions."
In addition, I just finished to edit visual RibbonCombobox and its relative controls by using the decompiler mentioned above, which decompiled the entire Ribbon library including original Microsoft .XAML themes.
Related
I'm wondering how I can extract (get a copy) of the Default Template of a given control using Visual Studio. I know this can be done with Expression Blend (right click a control, "Edit Template" -> "Edit a Copy...") which then copies the default control template in my Xaml. But can this be done with Visual Studio at all?
2015 update with clear instructions
In Visual Studio 2013, you can get the default ControlTemplate of a control in a few simple steps.
In the WPF designer, select the relevant control, or place the mouse cursor on the relevant control in the XAML.
Press F4 to open the Properties Window.
Open the Miscellaneous category to find the Template property, or type Template in the search field at the top of the Window.
Click on the little square to the right of the Template field and select the Convert to New Resource... option:
In the popup dialog, name the new ControlTemplate to be added and decide where you want it to be defined:
Click on the OK button.
EDIT >>>
In Visual Studio 2019 and later, this option seems to be disabled for some reason. A workaround can be found by right-clicking the control in the design view and selecting "Edit Template", then selecting "Edit a Copy...".
From Visual studio - right click the control, choose properties,
In the properties window look for the Template Property and right click it,
choose Extract Value To Resource
That will create a copy of the template in the XAML for you to work on.
Just to update this question, in VS 11 the XAML designer allows you to do this just like Expression Blend.
One thing to keep in mind: if you already have a style defined somewhere that targets the given control then all of the above described options will be disabled. I had the following bit of code in my App.xaml file:
<Application.Resources>
<Style TargetType="Button">
<Setter Property="IsTabStop" Value="False"/>
</Style>
</Application.Resources>
I was pulling my hair out trying to figure out why the edit a copy... and convert to new resource... options described in the other answers were disabled for my Button (which was defined in a completely different file). I commented out the above style code for Button and suddenly both options weren't disabled anymore.
Moral of the story: VS won't generate a style containing a template copy for you if a style already exists for that element anywhere in your code.
In VS19 I wasn't able to do this through properties.
However, I was able to right click the control in design mode Edit Template and Edit a Copy.
As far as I know it's not possible. However, you can use Show Me The Template to view the default template for a given control.
I was able to add an item using the Window Handler and such, but I also want to remove the already existing items (the window tool window inside of our main app, and we don't want all those options there). In the screenshot below it shows the one I added and the ones I want to remove (pretty much all of them). Let me know if there's a way to do this.
EDIT:
Or better yet, how to put my own context menu with XAML (if possible). But I don't want to lose the title bar or the aero effect.
Thanks!
I know this answer is slightly different than what you are asking, but it may help. You are wanting to modify the built-in menu from the window title bar... but what if you overlay that menu with your own using custom chrome (like how mozilla firefox/MS Office does it)?
To do this, download WPF Shell Integration Library from http://archive.msdn.microsoft.com/WPFShell and play around with it. The library also includes a few other cool features like jump lists.
more documentation on this technique is at http://blogs.msdn.com/b/wpfsdk/archive/2008/09/08/custom-window-chrome-in-wpf.aspx
You can create your own ContextMenus in WPF
<Grid>
<Grid.ContextMenu>
<ContextMenu>
<MenuItem Header="Dock" Command="{Binding ...}" />
</ContextMenu>
</Grid.ContextMenu>
</Grid>
Just be careful with the Bindings because WPF ContextMenus are not part of the same Visual Tree as the rest of your controls, so bindings do not work as expected. You will probably need a relative source binding to the PlacementTarget to get your command.
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.
I'm using Visual Studio 2010 and in a WPF app I'm using an expander. The prob is that the GroupBox etc inside the Expander are hidden from view in the Design window.
Any ideas to have them show?
Thx!
Well, this is old post so Gregg might already have answer to this. But, I'd like post answer because this might help others who stumbled across this issue.
The reason for expander not expanded in design view of VS 10 is that it's styled with user defined style like this:
<Expander Header="Layout"
IsExpanded="True"
Style="{StaticResource ExpanderStyle_Normal}">
</Expander>
So, there are two solutions:
Either, remove the Style attribute.
or/better
Set the Visibility to "Visible" in contentpresenter of controltemplate of that style.
< ContentPresenter Visibility="Visible" />
Note: Both workarounds are only meant for designing phase so when you're done with it, you need to revert back to the setting that's needed for the run-time.
I did some searching but it wasn't what I was looking for. So, does anyone know a way how to style the validation tooltip in Silverlight(the thing in the green border)?
alt text http://img689.imageshack.us/img689/222/validationtooltip.png
Any help would be greatly appreciated!
Best Regards,
~K
Unfortunately you can't easily provide a style for the validation tooltip without effectively styling the entire Textbox control. Blend makes this fairly easy if you are familiar with using that design tool. However if your a dyed in the wool coder like me then...
Goto this page on MSDN TextBox Styles and Templates
Copy the vsm namespace alias to your UserControl xaml
Copy the TextBox style into UserControls.Resources give it at an x:Key name (say MyTextBoxStyle")
Copy the ValidationToolTipTemplate from the web page to the UserControls.Resources, paste it above the TextBox style. It already has an x:Key name that the TextBox style will be referencing.
Add Style="{StaticResource MyTextBoxStyle}" to your TextBox in the data grid.
Now you play around with the validation elements of the templates to get your desired result.
The validation messages are displayed as a visual state. you can get to these (and edit them) as templates directly from blend.