4

さて、私はそれを行うためにこのコードを見ました:

<DataGrid.RowStyle>
    <Style TargetType="DataGridRow">

        <Style.Triggers>
            <Trigger Property="IsSelected" Value="True">
                <Setter Property="Background" Value="Black"/>
                <Setter Property="Foreground" Value="Green">
                </Setter>
            </Trigger>
        </Style.Triggers>

        <Setter Property="Background">                        
            <Setter.Value>
                <MultiBinding Converter="{StaticResource ucComponentesColorFilaMultiValueConverter}">
                    <Binding ElementName="dgdComponentes" Path="ItemsSource" />
                    <Binding ElementName="dgdComponentes" Path="SelectedItems" />
                    <Binding ElementName="CurrentItem" />
                </MultiBinding>
            </Setter.Value>
        </Setter>
    </Style>
</DataGrid.RowStyle>

実際には、コードはスタイルトリガーであり、setterプロパティは他の場合用ですが、このコードを追加すると、結果に影響を与える可能性があります。

選択した行の背景を変更したいのですが、デフォルトでは青ですが、条件に応じて他の色に変更したいと思います。たとえば、レジ​​スタが追加された場合、行を選択すると緑色になり、この行が選択されていない場合は薄緑色になります。

行の色は好きなように変更できますが、選択すると常に青色になります。

ありがとう。

4

2 に答える 2

15

あなたは多分このような何かを試すことができます...

       <SolidColorBrush x:Key="{x:Static SystemColors.HighlightBrushKey}" Color="Transparent" />
       <SolidColorBrush x:Key="{x:Static SystemColors.ControlBrushKey}" Color="Transparent" />
于 2012-07-27T19:17:23.917 に答える
0

このためには、プログラムで行の色を割り当てる必要があります

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

グリッドにバインドされているオブジェクトにBgColorプロパティを追加します。あなたの条件でBgColorを設定します(つまり、オブジェクトがレジスターの場合、BgColorは「緑」です)

于 2012-07-27T19:06:55.687 に答える