Projekt-Anfragen: Tel: 07022/9319004 info@CodeDocu.de Software Entwicklung in C# WPF Asp.Net Core Vba Excel Word SQL-Server EF Linq, UWP Net
#

WPF: Ausgewählte Zeile anpassen

 

Wie kann man die Farbe der selectierten Zeile und Zellen in WPF anpassen

 

Lösung:

Man muss im DataGrid die Style Eigenschaften für DataGridRow und DataGridCell einstellen

 

<DataGrid.RowStyle>

                <Style TargetType="DataGridRow">

                    <Style.Triggers>

                        <Trigger Property="IsSelected" Value="True">

                            <Setter Property="Background" Value="Blue"/>

                        </Trigger>

                    </Style.Triggers>

                </Style>

            </DataGrid.RowStyle>

            <DataGrid.CellStyle>

                <Style TargetType="DataGridCell">

                    <Style.Triggers>

                        <Trigger Property="IsSelected" Value="True">

                            <Setter Property="Background" Value="Red"/>

                        </Trigger>

                    </Style.Triggers>

                </Style>

            </DataGrid.CellStyle>

 

 

 

 

BeispielCode in WPF xaml des 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.RowStyle>

                <Style TargetType="DataGridRow">

                    <Style.Triggers>

                        <Trigger Property="IsSelected" Value="True">

                            <Setter Property="Background" Value="Blue"/>

                        </Trigger>

                    </Style.Triggers>

                </Style>

            </DataGrid.RowStyle>

            <DataGrid.CellStyle>

                <Style TargetType="DataGridCell">

                    <Style.Triggers>

                        <Trigger Property="IsSelected" Value="True">

                            <Setter Property="Background" Value="Red"/>

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

 

 

 

Mobile
»
WPF Datagrid: Farbe der Selektierte Zeile anpassen
»
WPF: Selected Row Farbe ändern bei DataGrid
»
WPF Uhrzeit Elemente oder DateTime-Picker
»
WPF: Scollbar anzeigen
»
WPF: Column oder Row ermitteln
»
WPF: SelectedItem aus DataGrid auslesen mit Anonyous Type auf Dyamic Type
»
WPF: Elemente zu breit, rand abgeschnitten
»
Gelöst: System.InvalidCastException HResult=0x80004002 SelectedItem SelectedValue
»
WPF Kurze Zeit in Grid Spalten anpassen. Anzeige Zeit Format
»
WPF: Combobox Selected Value ermitteln und zuweisen

.

Jobs, Projekte, Angebote für Freiberufler, Selbstständig an Info@CodeDocu.de