gpt4 book ai didi

c# - 如何在 DataGrid Mahapp 中更改选定行的颜色

转载 作者:行者123 更新时间:2023-11-30 21:56:42 25 4
gpt4 key购买 nike

我正在尝试更改所选行的颜色,但无法成功。我试过这个:

<DataGrid Style="{StaticResource AzureDataGrid}">

但我能看到的唯一变化是第一列用天蓝色着色。当我选择一行时,它变成白色,我看不到所选行的值。我是这个 framework 主题 wpf 的新手,文档不准确。有人可以帮助我吗?

最佳答案

现在可以使用最新的 MahApps.Metro Alpha 版本(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>

enter image description here

关于c# - 如何在 DataGrid Mahapp 中更改选定行的颜色,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31288162/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com