[英]How to change selected row color in DataGrid Mahapp
我正在嘗試更改所選行的顏色,但無法實現。 我已經嘗試過了:
<DataGrid Style="{StaticResource AzureDataGrid}">
但我唯一能看到的變化是第一列用天藍色着色。 當我選擇一行時,它將變為白色,並且看不到所選行的值。 我是這個framework
主題wpf的新手,並且文檔不准確。 有人能幫我嗎?
現在可以使用最新的Alpha版本的MahApps.Metro(1.1.3.x或更高版本1.2.0)來更改選定的行畫筆。
這是主要演示的示例
<DataGrid x:Name="MetroDataGrid"
Grid.Column="1"
Grid.Row="1"
RenderOptions.ClearTypeHint="Enabled"
TextOptions.TextFormattingMode="Display"
HeadersVisibility="All"
Margin="5"
SelectionUnit="FullRow"
ItemsSource="{Binding Path=Albums}"
AutoGenerateColumns="False">
<DataGrid.Columns>
<DataGridCheckBoxColumn ElementStyle="{DynamicResource MetroDataGridCheckBox}"
EditingElementStyle="{DynamicResource MetroDataGridCheckBox}"
Header="IsSelected"
Binding="{Binding RelativeSource={RelativeSource AncestorType=DataGridRow}, Path=IsSelected, Mode=OneWay}" />
<DataGridTextColumn Header="Title"
Binding="{Binding Title}" />
<DataGridTextColumn Header="Artist"
Binding="{Binding Artist.Name}" />
<DataGridTextColumn Header="Genre"
Binding="{Binding Genre.Name}" />
<controls:DataGridNumericUpDownColumn Header="Price"
Binding="{Binding Price}"
StringFormat="C"
Minimum="0" />
</DataGrid.Columns>
<DataGrid.Style>
<Style BasedOn="{StaticResource MetroDataGrid}"
TargetType="{x:Type DataGrid}">
<Setter Property="AlternatingRowBackground"
Value="{DynamicResource GrayBrush10}" />
</Style>
</DataGrid.Style>
<DataGrid.RowStyle>
<Style BasedOn="{StaticResource MetroDataGridRow}"
TargetType="{x:Type DataGridRow}">
<Style.Triggers>
<DataTrigger Binding="{Binding Price, Mode=OneWay, Converter={StaticResource AlbumPriceIsTooMuchConverter}}"
Value="True">
<Setter Property="Background"
Value="#FF8B8B" />
<Setter Property="Foreground"
Value="Red" />
</DataTrigger>
<!-- IsMouseOver -->
<MultiDataTrigger>
<MultiDataTrigger.Conditions>
<Condition Binding="{Binding Price, Mode=OneWay, Converter={StaticResource AlbumPriceIsTooMuchConverter}}"
Value="True" />
<Condition Binding="{Binding Path=IsMouseOver, RelativeSource={RelativeSource Self}}"
Value="true" />
</MultiDataTrigger.Conditions>
<Setter Property="Background"
Value="#FFBDBD" />
</MultiDataTrigger>
</Style.Triggers>
</Style>
</DataGrid.RowStyle>
<DataGrid.RowValidationRules>
<ValueConverter:AlbumPriceIsReallyTooMuchValidation ValidatesOnTargetUpdated="True"
ValidationStep="CommittedValue" />
<ValueConverter:AlbumPriceIsReallyTooMuchValidation ValidatesOnTargetUpdated="True"
ValidationStep="UpdatedValue" />
</DataGrid.RowValidationRules>
</DataGrid>
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.