CodeDocu.com

WPF: Selected line without focus

 

How to adjust the color at a datagrid when it has no focus

 

Solution:

You have to set the highlight colors instead of static colors

 

<DataGrid.CellStyle>

                <Style TargetType="DataGridCell">

                    <Style.Triggers>

                        <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>

                    </Style.Triggers>

                </Style>

            </DataGrid.CellStyle>

 

 

WPF Datagrid: Set Color of Row when it has no Focus

 

 

In complete code example xaml wpf datagrid

 

<DataGrid x:Name="ctlDataGrid" VerticalAlignment="Stretch" HorizontalAlignment="Stretch"

                 AutoGenerateColumns="False"

                 GridLinesVisibility="All"

                 Background="#F0f0f0" 

                 SelectionMode="Single" 

                 IsReadOnly="True" 

                 MouseDoubleClick="ctlDataGrid_MouseDoubleClick"

                  SelectionChanged="CtlDataGrid_SelectionChanged"

                  HeadersVisibility="All"                  

                  Grid.Row="1" 

                  SelectionUnit="FullRow"                   

                 >

            <DataGrid.CellStyle>

                <Style TargetType="DataGridCell">

                    <Style.Triggers>

                        <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>

                    </Style.Triggers>

                </Style>

            </DataGrid.CellStyle>

            

            <DataGrid.Columns>

                <DataGridTextColumn Header="ID" Binding="{Binding IDFeiertag}"/>

                <DataGridTextColumn Header="Datum" Binding="{Binding Datum_Feiertag}" Width="90"/>

                <DataGridTextColumn Header="Feiertag" Binding="{Binding Feiertag}" Width="140"/>

                <DataGridTextColumn Header="Kurz" Binding="{Binding Kurz}">

                    <DataGridTextColumn.CellStyle>

                        <Style TargetType="DataGridCell">

                            <Setter Property="Background" Value="{Binding Farbe}" />

                            <Setter Property="Foreground" Value="{Binding Textfarbe}" />

                        </Style>

                    </DataGridTextColumn.CellStyle>

                </DataGridTextColumn>

 

 

            </DataGrid.Columns>

        </DataGrid>

 

 


Software Entwicklung Stuttgart NĂ¼rtingen
Suche Projekte C#, WPF, Windows App,ASP.Net, vb.Net, WinForms, SQL Server, Access, Excel