This seems like it's far more difficult than it should be, but I'd like to set the background color of a dropdown combobox programmatically (ie. if the user selects one value, I'd like it to appear red, otherwise blue...)
What I've noticed is that if you just set the Background property to a SolidColorBrush, the only thing that seems to change is that slight-glow that the ComboBox has.
I know that the ComboBox is constructed of multiple objects, and that it takes more than just setting the BackgroundColor, but I'm just wondering if there's a simple way of doing this programatically, where the entire background changes colors, instead of the glow.
Unfortunately most of the colors involved are hardcoded into the combox style. Hence the only way you are going to achieve greater control over the color used is to copy out the entire ComboBox style and simplify the set of Rectangle elements named Background.....
Related
I'm developing a WPF project where I need to validate textboxes on code-behind and then change the border color of those textboxes to some unknown color defined by the user configuration; the problem is that to overwrite the MouseOver effect I would need to set the value from XAML directly via ControlTemplate or Style.
Is there a way to get the current value assigned to the TextBox from XAML? Maybe binding it to itself?
I will appreciate any help you can give.
When validating a TextBox, or any control for that matter, it's common to use an adorner to display the validation error (in your case, setting the border color). You can have a look at an example here.
Using this method, you don't actually change the TextBox's border, but create a new visual layer on top of the TextBox that draws the new border around it. This is pretty much the way validations should be done in WPF, and it also solves your problem of having to deal with changing the TextBox's border value back and forth.
I'm fairly new to Silverligt 5 and xaml for that matter and I have come across a problem. I have a datagrid containing a template column. This template consists in a bunch of TextBlocks, images and other controls. I've customized the way the grid looks by overriding the grid/row/cell style using the VisualStateManager. Everything works fine when changing for instance the row background and borders on MouseOver. However I didn't find a way to change the foreground color of just one of the TextBlocks in the column template. So I'm not trying to set the foreground of the cell it self but only for one of the many controls(a TextBlock) in the column template. When the user is hovering a grid row, I want - apart from changing the background of the entire row, to also change the foreground color of this particular TextBlock.
Hope this makes sense
You need define style for DataGridColumnHeader Template
look here : MSDN
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 working in Silverlight, trying to figure out how to set a grid cell font color based on the contents of the cell.
I have an ObservableCollection bound to a DataGrid, and my items implement INotifyPropertyChanged so the grid updates as I change the values; it's all working perfectly, including letting me sort items and keep the sorting while I update the underlying items.
I know I can use the LoadingRow event to change colors, but the only way I can get the event to fire is by changing the grids datasource, in which case my sorting goes out the window.
So, what I really want is a way to either
loop the rows in the datagrid,
find the cell I need, and change
it's color or
implement a custom
column that I can use to dynamically
set the color.
The problem is how to actually do either of those things :).
You should use databinding for this.
Bind your cell font color to the content of the cell
Create a converter IValueConverter that converts the value to a color depending from your needs
See here for a good example
http://weblogs.asp.net/joewrobel/archive/2009/01/25/conditional-formatting-in-the-silverlight-datagrid.aspx
Basically my problem stems from a desire to have the textbox portion be white, and the drop down to be black. When I set the text to white, the drop down appears as I want it, but the text in the textbox itself is hardly readable. Setting the Foreground to black makes the drop down unreadable.
Is there a good way to handle this? I am still learning WPF.
Edit the ControlTemplate, You will see a TextBlock and another PopUp which again has a set of controls. Have a different ForeGround/Background for this TextBox,
Your best bet is to edit a copy of the template of the ComboBox and set the two of them independently.