1

TextBox とデータグリッドがあります。テキストボックスと同様の値を持つデータグリッド内の列「Omschrijving」からセルの背景色を変更する必要があります。

この問題にカスタム コンバーター クラスを使用することはできません。したがって、これを XAML コードまたはページのクラスでのみ解決する必要があります。

コード例:

<TextBox x:Name="txtTrefwoord"/>

<DataGrid x:Name="gridFiche" ItemsSource="{Binding}">
  <DataGrid.Columns>
    <DataGridTextColumn Binding="{Binding Omschrijving}" Header="Omschrijving" />
  </DataGrid.Columns>                    
</DataGrid>

スクリーンショットの例:

ここに画像の説明を入力

4

1 に答える 1

-1

テキストに応じて色を決定する根拠が単純な場合 (例のように - 2 種類のテキスト)、テキストが "..." の場合は背景を "..." に設定するというトリガーを使用できます。

<DataGridTextColumn Binding="{Binding Omschrijving}" Header="Omschrijving" >
    <DataGridTextColumn.CellStyle>
        <Style TargetType="DataGridCell">
            <Style.Triggers>
                <DataTrigger Binding="{Binding ElementName=txtTrefwoord, Path=Text}" Value="{Binding RelativeSource={RelativeSource Self}, Path=Text }" >
                    <Setter Property="Background" Value="Red" />
                </DataTrigger><!--not sure that's the path-->
            </Style.Triggers>
        </Style>
   </DataGridTextColumn.CellStyle>
</DataGridTextColumn>

そんな感じ。確認せずに頭から書きます。

于 2013-10-17T13:45:57.733 に答える