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.
Related
Now I just want to dropdown the combobox via code.
IsDropDownOpen = true;
So how to hide (not disable) the arrow button in combobox?
To hide the ComboBoxToggleButton, you would have to edit a copy of the combobox template.
Right click on the combobox and select edit template. Select edit a copy and give it a name. (You may want to put the copy in a resource dictionary of it's own considering the content size)
The generated ComboBox style will have reference to two templates, ComboBoxTemplate and ComboBoxEditableTemplate.
In each template, you will find a ToggleButton with x:Name:toggleButton, that is the toggle button you want to hide.
You can remove it entirely, or make use of your WPF given Visibility property. Your call ;)
I would consider putting a textbox on top of the combobox and hiding that part of it.
Something like:
<Grid>
<ComboBox Name="YourCombo"/>
<TextBox Name="VisibleValueTextBox"/>
</Grid>
You can bind the text of VisibleValueTextBox to that of YourCombo.
When you drop it down, the dropdown will still be on top of everything.
I'm not sure what your full requirements are but this is a quick and perhaps rather dirty approach which could work.
I want to change the display behavior of the selected item(s) in a WPF Listview. Specifically, I want to retain the custom textblock foreground colors that I've applied and apply a border around the item.
I am able to alter SystemColors.HighlightBrushKey and ControlBrushKey to change the background color of the selected item, but I don't know how to get it to stop changing the font color or use a border instead. I've tried manipulating the control template and have also searched Google for examples of how to do this, without success.
yeah, looks like you have to go through the pain of using ControlTemplates.
Good news is that via using Expression Blend, you can get current ControlTemplate for ListView and tweak the bit that you need and use that as your default ControlTemplate.
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.
I have a datagrid. Within that datagrid, I have bunch of column headers styles. Inside the control template of this style, there is a button. I need to bind a command to that button.
Note that, there is also a TextBlock within the header style which I bind using element to element binding, as I will not have my viewModel in the header's dataContext.
If I use the same idea to bind the button command, it doesnt work. Am I missing something?
If this is unclear, please let me know and I will post sample code.
Thanks in advance!
Sample code always helps :-)
Remember that each data row in your grid is bound to an item with your datagrid datacontext. If your command does not exist in your item class (which it probably shouldn't) then it won't get bound correctly.
Can you trigger your command from the SelectedItem changed property of your datagrid, rather than an internal button? You can do this with the following code: http://thoughtjelly.blogspot.com/2009/12/silverlight-commands-data-grid-row.html