I have a style for a control and I'd like to add items to the context menu of that control. I was able to replace the context menu with my own but have found no way to add items to the existing one. Is this possible in XAML?
Thanks!
You can always toggle a MenuItem's visibility in XAML using bindings. This allows you to create one context menu but control the options displayed to the user entirely through XAML. This is what I've done in the past as it seems to be the easiest option.
Related
I need to write a style for a listboxItem that will add a button on the right of the listboxitem when it is selected or mouse over. The button need to have a command binding as well .
This style need to be used in different places.
also the button won't have a border. but when the mouse is over the button , it will have a border.
How can i write this?
I tried to write a style, but i can't bind to the command of the button that is inside the style.
Code used: (sorry i wasn't able to paste my code normally here so it is here http://justpaste.it/1b9s)
It would be great to see some code but an option that should work is to create a DataTemplate. You can set it on ListBox ItemTemplate property and use it in the different locations where you may need it.
I’m building a user control that has a context menu with several items, and I want the users of that control to be able to append items to that context menu.
I thought of adding an attached property where users can specify menu items, but I couldn’t find a way to easily add these items (e.g. in an ItemsControl container) to the control’s ContextMenu in an MVVM way (i.e. using binding and not code-behind).
Do you have an idea how this can be done?
If you have Dictionary<int,MenuItem> and you will have a place that user can select menus. Then add selected menu items to ContextMenu when your control loaded.
I hope this helps.
I've got a ListView, whose View is switched dynamically in runtime between an Icon mode and a Grid mode (the latter implemented with a GridView).
The problem is, as I described here, that when I add ListView.GroupStyle in my ListView definition, the Icon mode gets screwed. Hence, I'd like to reset/disable GroupStyle for that mode.
So, my question: is there a way to apply/reset the GroupStyle dynamically (via a Trigger?) when I switch the ListView into the Grid mode?
I tried to do that (e.g. <Setter Property="ListView.GroupStyle" Value="{x:Null}"/>) for the Icon View, but this doesn't compile because "The Property Setter 'GroupStyle' cannot be set because it does not have an accessible set accessor."
Any suggestions will be cordially welcome :-)
There could be two ways to do this...
Instead of setting the GroupStyle to x:Null keep the existing set GroupStyle as it is, but reset its inner template using DataTriggers that use TemplateBinding.
Use bottom up approach, remove your GroupDescriptions from your CollectionView based on the mode.
I'm trying to create a button in main window that would look like a globe, which would allow user to select his/her location. I want it to display a listBox when clicked on it just below the button itself.
Any hints on how to do this?
Probably the simplest way to do this is restyle a ComboBox and then restyle the ToggleButton in the ComboBox and remove the editable textbox.
This will avoid you having the implement the functions of the ComboBox for your popup.
Try using this as a starting point.
Another Approach would be to use the Expander Control with a list box in it
Link
OR
You could play with the Listbox's visibility property
Is there any property or state I can set on a expander object that makes it unexpandable but still can be selected?
I'm thinking for example of the last Child in a TreeView where I don't wan't the Expander to have an expander button. But other uses could be if someone doesn't have access to more then the header or something along that line.
The only way I know would be to create custom control template for expander, remove expander button from it and disable expanding.
See WPF Expander: Reversing the icon direction while keeping the content location (ExpandDirection) the same on how to create custom template for expander.