Disable focus on header - listview wpf - wpf

I'm using wpf and I've listview.
Everything just works fine, but I want to disable focusing on header (when i enter header with mouse it changes color to blue).
I mean this

This will do the work.
<GridView.ColumnHeaderContainerStyle>
<Style TargetType="{x:Type GridViewColumnHeader}">
<Setter Property="IsEnabled" Value="False"/>
<Style.Triggers>
<Trigger Property="IsEnabled" Value="False">
<Setter Property="TextElement.Foreground" Value="Black"/>
</Trigger>
</Style.Triggers>
</Style>
</GridView.ColumnHeaderContainerStyle>

Related

Removing box / border around selected cell contents in WPF DataGrid

Trying to restyle a WPF datagrid. Almost where I need to be, except for one peculiarity: when selecting a row, the contents of all the cells are surrounded by a white border.
I'm at a loss as to how to get rid of this. At the moment, my styling looks like this:
<Style TargetType="{x:Type DataGridRow}">
<Setter Property="Background" Value="Transparent" />
<Setter Property="BorderBrush" Value="Transparent" />
<Setter Property="FocusVisualStyle" Value="{x:Null}"/>
<Style.Triggers>
<Trigger Property="IsSelected" Value="True">
<Setter Property="Background" Value="#3CACDC" />
<Setter Property="Foreground" Value="White" />
</Trigger>
<Trigger Property="IsMouseOver" Value="True">
<Setter Property="Background" Value="#90C8E0" />
</Trigger>
</Style.Triggers>
</Style>
Plus DataGridCell has an almost identical style set.
It's not clear whether the question How to suppress DataGrid cell selection border? is asking the same question, but the accepted solution of setting FocusVisualStyle to Null doesn't remove the border. It does, however, change the style:
How can I get ride of that border?
I think you can try styling DataGridCell style
<DataGrid.CellStyle>
<Style TargetType="DataGridCell">
<Setter Property="BorderThickness" Value="0"/>
<Setter Property="FocusVisualStyle" Value="{x:Null}"/>
</Style>
</DataGrid.CellStyle>

RowStyle in DataGrid working only partially

This is weird, so I'm sure I'm missing something (almost) obvious here. I wish to control the appearance of the selected row and cell so I'm playing with the triggers. The triggering seems to work, because I see the settings I've maid with regarding the colors and thickness.
<DataGrid.RowStyle>
<Style TargetType="DataGridRow">
<Style.Triggers>
<Trigger Property="IsSelected" Value="True">
<Setter Property="Background" Value="Aquamarine"></Setter>
</Trigger>
</Style.Triggers>
</Style>
</DataGrid.RowStyle>
<DataGrid.CellStyle>
<Style TargetType="DataGridCell">
<Style.Triggers>
<Trigger Property="IsSelected" Value="True">
<Setter Property="BorderThickness" Value="0"></Setter>
</Trigger>
</Style.Triggers>
</Style>
</DataGrid.CellStyle>
However, the problems is that the rows' background is colored in the default blue on all the columns containing data and in my custom aquamarine on the empty space to the right of the last column, just like the image below depicts.
What gives? My google-fu haven't shown anything about persistent defaults needed to be removed...
The default blue coloring is part of the DataGridCell's Template.
You can retemplate the DataGridCell and omit this functionality, or you can instead just add a setter in your existing DataGridCell style's IsSelected trigger and set the Background to Transparent.
<DataGrid.CellStyle>
<Style TargetType="DataGridCell">
<Style.Triggers>
<Trigger Property="IsSelected" Value="True">
<Setter Property="BorderThickness" Value="0"/>
<Setter Property="Background" Value="Transparent"/>
</Trigger>
</Style.Triggers>
</Style>
</DataGrid.CellStyle>

How to inherit custom Textblock style in wpf datagrid?

I have TextBlock in the DataGridTemplateColumn in WPF Datagrid. when I check "IsEnable" false to inherit the Textblock Style inside the DatagridTemplateColumn. Here is XAML code i'm using:
<Style TargetType="{x:Type DataGrid}" >
<Setter Property="Template" >
<Setter.Value>
<ControlTemplate TargetType="{x:Type DataGrid }">
<ControlTemplate.Resources >
<Style TargetType="{x:Type TextBlock }">
<Style.Triggers>
<Trigger Property="IsEnabled" Value="False">
<Setter Property="Foreground" Value="{StaticResource {x:Static SystemColors.GrayTextBrushKey}}"/>
</Trigger>
</Style.Triggers>
</Style>
</ControlTemplate.Resources>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
This did not work and later i tried:
<Style TargetType="TextBlock" >
<Style.Triggers>
<Trigger Property="IsEnabled" Value="False">
<Setter Property="Foreground" Value="{StaticResource {x:Static SystemColors.GrayTextBrushKey}}" />
</Trigger>
</Style.Triggers>
</Style>
Any Thoughts on how to check if the Texblock inside the Datagrid "IsEnabled" and inherit the Style?.
WPF does not apply implicit styles inside templates unless the TargetType derives from Control. Since TextBlock doesn't derive from Control, its style is not applied. So you either have to manually apply the style to every non-Control or define the implicit style inside the template.
Define your styles inside datagrid resources as
<DataGrid.Resources>
<Style TargetType="{x:Type TextBlock}">
<Style.Triggers>
<Trigger Property="IsEnabled" Value="False">
<Setter Property="Foreground" Value="Red"/>
</Trigger>
</Style.Triggers>
</Style>
</DataGrid.Resources>
I'm going to assume you are trying to toggle the foreground color based on the IsEnabled state of the TextBlock.
Where are you setting the IsEnabled = true Foreground color? You have not given the code for the actual TextBlock you are going to style.
Try this:
<Style TargetType="{x:Type TextBlock}">
<Style.Triggers>
<Trigger Property="IsEnabled" Value="True">
<Setter Property="Foreground" Value="Red" />
</Trigger>
<Trigger Property="IsEnabled" Value="False">
<Setter Property="Foreground" Value="Green" />
</Trigger>
</Style.Triggers>
</Style>
If this doesn't work, it means wherever your Textblock is defined, you are doing this -
<TextBlock .... Foreground="SomeColor" />
and you need to remove the Foreground setting directly on the TextBlock so that the Foreground color can be set by the style.

WPF DataGrid RowStyle for selected row not changing the background and foreground color

I am using Visual Studio 2012 on windows 7. I need to know why the following style for Grid's selected row does not work for background and foreground colors but works perfectly fine for other properties like BorderBrush and BorderThickness etc? Though I can see them changing while mouse over grid rows.
<Style x:Key="gridRowStyle" TargetType="{x:Type DataGridRow}">
<Style.Triggers>
<Trigger Property="IsMouseOver" Value="True">
<Setter Property="Background" Value="PeachPuff"/>
<Setter Property="Foreground" Value="BlueViolet"/>
</Trigger>
<Trigger Property="IsSelected" Value="True">
<Setter Property="Background" Value="PeachPuff"/>
<Setter Property="Foreground" Value="BlueViolet"/>
<Setter Property="BorderBrush" Value="BlueViolet" />
<Setter Property="BorderThickness" Value="2" />
</Trigger>
</Style.Triggers>
</Style>
Here is how I am using on grid.
<DataGrid RowStyle="{StaticResource gridRowStyle}">
I am stressing on to know "why" rather than solution to the problem as I already have solution to problem if I use grid cell style instead of rowstyle like following:
<Style x:Key="gridCellStyle" TargetType="{x:Type DataGridCell}">
<Style.Triggers>
<Trigger Property="IsSelected" Value="True">
<Setter Property="Background" Value="PeachPuff"/>
<Setter Property="Foreground" Value="BlueViolet"/>
</Trigger>
</Style.Triggers>
</Style>
In the Default style of the DataGridCell having the following default style trigger.
<Trigger Property="IsSelected" Value="True">
<Setter Property="Background" Value="{DynamicResource {x:Static SystemColors.HighlightBrushKey}}"/>
<Setter Property="Foreground" Value="{DynamicResource {x:Static SystemColors.HighlightTextBrushKey}}"/>
<Setter Property="BorderBrush" Value="{DynamicResource {x:Static SystemColors.HighlightBrushKey}}"/>
</Trigger>
So if you written trigger for DataGridRow, then it will only apply to the element that was placed before the DataGridCell in visual tree.
So to change the Background & Foreground while selection, you must write the trigger in DataGridCell style or remove the default trigger from the style.
Simply remove this attributs at row level in the datagrid, they have priority over the trigged properties.
nezac

WPF ComboBox: background color when disabled

I currently use this style for my ComboBox in WPF:
<Style TargetType="ComboBox">
<Setter Property="Foreground" Value="White"/>
<Setter Property="Background" Value="#303030"/>
<Setter Property="BorderBrush" Value="#000000"/>
</Style>
How can I change it to specify the background color when the ComboBox is disabled?
(this is a follow-up to this question: WPF combobox colors)
<Style TargetType="ComboBox">
<Setter Property="Foreground" Value="White"/>
<Setter Property="Background" Value="#303030"/>
<Setter Property="BorderBrush" Value="#000000"/>
<Style.Triggers>
<Trigger Property="IsEnabled" Value="False">
<Setter Property="Background" Value="#101010"/>
</Trigger>
</Style.Triggers>
</Style>
I ended up using the style used here as a base, and this did allow to set the background color when disabled:
http://msdn.microsoft.com/en-us/library/ms752094%28v=VS.85%29.aspx

Resources