Restyling ComboBoxI dropdown gray and not selectable when ComboBox is ReadOnly - wpf

I have seen this post: WPF ComboBox: background color when disabled
and some others...
But This solution causes me some problems. All I want is to make the textBox gray, and the ComboBoxItems gray and not selectable. I don't want to recreate all the style as the control won't work properly on both XP and seven. I don't want to choose one style for both, but I want XP style for XP and seven style for seven.
Is there a way to set the style so I can change the Background of the ComboBoxItems when the comboBox is Readonly?
Thanks in advance!
Update: It seems that the Drop down popup should be restyled instead. I got to find how.

I finally found my answer at many places on the web, pieces by pieces. The ComboBox style is composed of other controls. The PopUp is the one that interests me. It is not public, so I can't modify it as I want. It would have been interesting to define a style for my popup and to replace the original popup by it, but it is not accessible, so... I attempted to make a template that inherits from the template of the original ComboBox, but that is not possible neither. It won't accept inheritance for some good reasons How to Inherit a Control Template. So the template must be remade totally or not. The other option would be to make my own control that inherits from combobox and that changes the items to gray and not selectable when the combobox is readonly (into the code), but this is not a good idea in my situation. No solution for me. I will have to stick with the whole template redifinition. I hope this post will help someone in some way!

Related

Want to style the comboboxes and scroll bars in my application

I've got Expression Blend 4 installed on my machine. I just need to know what I'm doing.
My application will be running on a laptop equipped with a touch screen, in police cars where the user will probably be driving the car. Needless to say, the interface has to be easy to use. In this case, that means things like the drop down buttons on ComboBox controls and scroll bars need to be wider than normal so they're easy for the driver to use.
Can someone tell me what part I have to change for each of these controls in order to get the effect I want? I tried editing a copy of the template for one of the combobox controls in one of my user controls and playing with the ToggleButton control but that didn't do what I wanted it to do. There's so much mark-up in the template it's hard to tell what's doing what.
Thanks for any help you can give.
Tony
Edit:
I figured it out from the first answer to this previous StackOverflow post. I had to make a copy of the ComboBox's style, then make a copy of the ToggleButton's style.
Thanks anyway.
Tony
The solution was to edit the application in Expression blend. I clicked on one of the ComboBoxes and right clicked. From the context menu, I selected Edit Template | Edit a copy. In the dialog box that appears, I specified that the new template should be applied to all ComboBoxes in the application.
Within the ComboBox's style, there's a ToggleButton. I repeated the above steps with the Togglebutton. Finally, I changed the width to make it what I wanted. There's also a path in there for the arrow that you can play with if you like.
Tony

Silverlight: Individual visibility of a RowDetailsTemplate for each data row

I'm trying to achive displaying the RowDetailsTemplate of a Silverlight DataGrid depending on a bool Property, bound to a CheckBox Control's IsChecked Property. Insinde of my RowDetailsTemplate there is a single custom UserControl, containing further Controls.
Since the DataGrid only allows a global setting (RowDetailsVisibilityMode) Some code-behind is needed. I've implemented a solution based on Rorys Reply (and using a behaviour-technique) which actually works.
Unfortunately, The DataGrid doesn't remember the individually shown or hidden Rows on sorting. The checkbox remains selected, but the Row collapses. Further, no event like "OnAfterSort" or something similar seems to exist, where i could "Refresh" the visibility settings in a loop.
Another idea was to bind the Visibility of my custom Details-UserControl to the CheckBox bound value. This actually works (when settings RowDetailsVisibilityMode to "Visible"), but I'm not able to get rid of this weird behaviour: When the CheckBox is checked, the Detail Template expands and the detail UserControl appears. Nice. When the CheckBox is unchecked again, the UserControl disappears (Visibility is set to Collapsed) but the Row doesn't collapse and the blank space remains (as it would be set to Hidden not Collapsed).
Do you have any ideas?
I hope it's ok I didn't post any code samples, the implementation is pretty easy and I believe that the problem doesn't actually lie in a coding mistake i made. You can setup a simple DataGrid quickly like in this perfect MSDN Example. Starting from here, it's easy to test both described behaviours!
Really big thanks in advance,
- Thomas

Change foreground/background color of Item in Listbox programmatically in WPF

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.

Dynamically Styling TreeViewItem? (Silverlight)

Hey all, I've noticed that if I have a style setup for a treeview, and a different one setup for the treeviewitem, it gets overridden once I put the item in the tree. Does anyone have suggestions for how to control the style of each treeviewitem individually while mantaining a default style that is applied to the whole treeview? Basically I want to make the text of my treeviewitem red depending on a data field in the item. Otherwise I want it to be black. Thanks
DataTemplateSelector is not in Silverlight. Try below link
http://blog.timmykokke.com/archive/2009/09/28/datatemplateselector-in-silverlight.aspx
Thanks, turns out it was TreeViewItem.Style CAN be set to an ItemContainerStyle if you use the objects as references.

Changing the style of a Combo-Box in WPF (in Blend preferably)

I'm having some issues trying to change the look / style of a combo box in Expression Blend / WPF. While there are tutorials out there describing setting styles for buttons, there seem to be a few wrinkles with ComboBox controls.
Can anyone offer any advice, or point me towards good tutorials that cover re-styling something more complex than a button?
The ComboBox style template has 3 parts to it.
The ContentPresenter you should have come across styling Buttons.
There is a Part_Popup that you should find easy to change properties on and style.
The last part is a ToggleButton, to style that you need to "edit a copy" again and create another new style template for the ToggleButton.
Have a look at BeaCostas SolarSytem Listbox it's a lovely piece of work.

Resources