I have a treeview structure. When I try to click on the nodes there is a blue color that shows the node selected. How can I remove that.
I don't want a selection color to be displayed on the tree.
ItemContainerStyle method does not work for me say on Windows-8. There are 4 brushes that generally correspond to this and are used by the default Template for TreeViewItem
keys:
HighlightBrushKey - Background with focus.
HighlightTextBrushKey - Foreground with focus.
InactiveSelectionHighlightBrushKey - Background without focus.
InactiveSelectionHighlightTextBrushKey - Foreground without focus.
Just override them as you see fit, for your requirement something like this would do fine:
<TreeView>
<TreeView.Resources>
<SolidColorBrush x:Key="{x:Static SystemColors.HighlightBrushKey}"
Color="Transparent" />
<SolidColorBrush x:Key="{x:Static SystemColors.HighlightTextBrushKey}"
Color="Black" />
<SolidColorBrush x:Key="{x:Static SystemColors.InactiveSelectionHighlightBrushKey}"
Color="Transparent" />
<SolidColorBrush x:Key="{x:Static SystemColors.InactiveSelectionHighlightTextBrushKey}"
Color="Black" />
</TreeView.Resources>
</TreeView>
Do pay attention to only overriding them within the scope you require. For example if you put all this into App.xaml you're going to see some weird side-effects as all control's using these Brushes would now end up using your overridden ones which may not be what you're after.
Related
In a scenario of a WPF form with multiple data grids, I have been (unsuccessfully) trying to conditionally change specific rows (background) color, which effect would signify to the user a optically detectable circumstance.
During trials although I have been able to set the (background) color correctly either by the use of Data triggers and bindings or by handling the LoadingRow event, the row style is getting dismissed when the grid controls lose focus.
As some people suggested the only way to by-pass this is by using the System.HighlightBrush which indeed works : despite the lost of focus, the rows of interest retain their style.
If I follow the aforementioned technique, is there a way to change the color of the HighlightBrush to something other than the standard system default light blue one?
Define your own brushes for HighlightBrushKey and InactiveSelectionHighlightBrushKey and put them in the Resources dictionary of the DataGrid:
<DataGrid ...>
<DataGrid.Resources>
<SolidColorBrush x:Key="{x:Static SystemColors.HighlightBrushKey}" Color="Transparent"/>
<SolidColorBrush x:Key="{x:Static SystemColors.InactiveSelectionHighlightBrushKey}" Color="Transparent"/>
<SolidColorBrush x:Key="{x:Static SystemColors.HighlightTextBrushKey}" Color="Black"/>
</DataGrid.Resources>
</DataGrid>
I am new to wpf and I wanted to change the ComboBox style to this However all I could do was to change the highlight color.
<ComboBox.Resources>
<SolidColorBrush x:Key="{x:Static SystemColors.WindowBrushKey}" Color="#FF374046" />
<SolidColorBrush x:Key="{x:Static SystemColors.HighlightBrushKey}" Color="#FF374046" />
</ComboBox.Resources>
If anyone could guide me to understanding how to create it I would be thankful.
Have a quick glance at http://www.wpfhelper.com/index.php/styles-in-wpf/combobox/15-combobox-style-in-wpf. As mentioned in the comments, you need to create your own custom style & template for the ComboBox, ComboBoxItem and ComboBox ToggleButton. Play around with the CornerRadius of the popup element, to start with.
Is it possible to set the selected text color for control like TextBox, ComboBox simply or do I have to setup a style trigger to change the selected text background.
I have a set of styles applied to the controls, but one of the things that isn't styled is the selected text, it's defaulted to a pale blue. I've tried setting some of the properties of the SystemColors class but this had no affect.
<SolidColorBrush x:Key="{x:Static SystemColors.HighlightColor}"
Color="Red" />
<SolidColorBrush x:Key="{x:Static SystemColors.HighlightColorKey}"
Color="Red" />
<SolidColorBrush x:Key="{x:Static SystemColors.HighlightBrushKey}"
Color="Orange" />
<SolidColorBrush x:Key="{x:Static SystemColors.HighlightBrush}"
Color="Orange" />
It sounds like you're looking for the TextBoxBase.SelectionBrush property
I'm using a ListBox to display a list of editable objects whose template contains, among other things, a ComboBox.
I used this common technique to hide the ListBox selection, which is not used for anything:
<ListBox.Resources>
<Style TargetType="ListBoxItem">
<Style.Resources>
<Brush x:Key="{x:Static SystemColors.HighlightBrushKey}">Transparent</Brush>
<Brush x:Key="{x:Static SystemColors.ControlBrushKey}">Transparent</Brush>
The problem is this messes with the ComboBox dropdown list selection.
I'd like to override these resources again in my template, specifying the original values (SystemColors.HighlightBrush, etc) instead of hardcoding them. How can I do that?
<ListBox.ItemTemplate>
<DataTemplate DataType="{x:Type SearchService:Criterion}">
<DataTemplate.Resources>
<!--I know how to specify a hardcoded brush here,
but not how to reference one from SystemColors-->
I used this common technique to hide
the ListBox selection, which is not
used for anything
If you do not use the selection for anything you should just use an ItemsControl instead.
You could do:
<SolidColorBrush x:Key="{x:Static SystemColors.HighlightBrushKey}"
Color="{x:Static SystemColors.HighlightColor}" />
<SolidColorBrush x:Key="{x:Static SystemColors.ControlBrushKey}"
Color="{x:Static SystemColors.ControlColor}" />
or
<SolidColorBrush x:Key="{x:Static SystemColors.HighlightBrushKey}"
Color="{DynamicResource {x:Static SystemColors.HighlightColorKey}}" />
<SolidColorBrush x:Key="{x:Static SystemColors.ControlBrushKey}"
Color="{DynamicResource {x:Static SystemColors.ControlColorKey}}" />
To restore the brushes to their default colors.
I want to ensure that a selected ListViewItem's non-focused background is the same as the focused background. I know that the common way of doing this is as follows:
<SolidColorBrush x:Key="{x:Static SystemColors.HighlightBrushKey}" Color="Blue"/>
<SolidColorBrush x:Key="{x:Static SystemColors.ControlBrushKey}" Color="Blue"/>
However, the problem is that I don't want to specify a colour, I merely want the Brush returned by the static resource whose key is ControlBrushKey to be the same as the one for HighlightBrushKey.
The answer is this:
<SolidColorBrush x:Key="{x:Static SystemColors.ControlBrushKey}"
Color="{DynamicResource {x:Static SystemColors.HighlightColorKey}}" />
Try this... I know it works to set two properties to match, not sure if it will work in your context, but it's worth a shot:
<SolidColorBrush x:Key="{x:Static SystemColors.HighlightBrushKey}"
Color="Blue"/>
<SolidColorBrush x:Key="{x:Static SystemColors.ControlBrushKey}"
Color="{DynamicResourse SystemColors.HighlightBrushKey.Color}"/>
I tested this using a TextBox as a playground. I'm not sure of your exact application, but here was my test markup:
<TextBox>
<TextBox.Background>
<SolidColorBrush x:Key="{x:Static SystemColors.HighlightBrushKey}"
Color="Blue"></SolidColorBrush>
</TextBox.Background>
<TextBox.Foreground>
<SolidColorBrush x:Key="{x:Static SystemColors.ControlBrushKey}"
Color="{DynamicResource SystemColors.HighlightBrushKey.Color}" />
</TextBox.Foreground>
</TextBox>
This just set the background to blue, and the foreground to the background, which was the expected result.