2016-09-13 13 views
0

のプロパティに列ヘッダをバインドしようとすると:は、私が現在持っている私のC#コード

<Window x:Class="Client_SCM.MainWindow" 
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" 
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" 
    xmlns:d="http://schemas.microsoft.com/expression/blend/2008" 
    xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 
    xmlns:local="clr-namespace:Client_SCM" 
    mc:Ignorable="d" 
    Title="Swords Call Monitor 2.0" Height="350" Width="474"> 

<Grid HorizontalAlignment="Stretch" 
     VerticalAlignment="Stretch" 
     Margin="5" 
     ShowGridLines="True"> 
    <DataGrid x:Name="dataGrid" 
       HorizontalAlignment="Stretch" 
       VerticalAlignment="Stretch" 
       Margin="5" 
       AlternatingRowBackground="Aqua" Loaded="dataGrid_Loaded" AutoGenerateColumns="False"/> 

</Grid> 

そして、私はそれには、このような何かを実装しようとしています:

<DataGridTextColumn Binding="{Binding WhateverIWantToDisplay}" > 

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

    <Style.Triggers> 
    <DataTrigger Binding="{Binding Foo}" Value="1"> 
     <Setter Property="Background" Value="Blue" /> 
    </DataTrigger> 

    <DataTrigger Binding="{Binding Foo}" Value="2"> 
     <Setter Property="Background" Value="Red" /> 
    </DataTrigger> 

    <DataTrigger Binding="{Binding Foo}" Value="2"> 
     <Setter Property="Background" Value="Yellow" /> 
    </DataTrigger> 

    </Style.Triggers> 
</Style> 

エラーは「プロパティ 'コンテンツ'は1回しか設定できません」というエラーが表示されます。

助けていただけたら幸いです!

答えて

0

DataGridTextColumnBindingの代わりにHeaderを使用してみてください。

<Window x:Class="Client_SCM.MainWindow" 
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" 
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" 
    xmlns:d="http://schemas.microsoft.com/expression/blend/2008" 
    xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 
    xmlns:local="clr-namespace:Client_SCM" 
    mc:Ignorable="d" 
    Title="Swords Call Monitor 2.0" Height="350" Width="474"> 

    <Grid HorizontalAlignment="Stretch" VerticalAlignment="Stretch" Margin="5" ShowGridLines="True"> 
     <DataGrid x:Name="dataGrid" HorizontalAlignment="Stretch" VerticalAlignment="Stretch" Margin="5" 
        AlternatingRowBackground="Aqua" AutoGenerateColumns="False"> 
      <DataGrid.Columns> 
       <DataGridTextColumn Header="{Binding WhateverIWantToDisplay}"> 
       </DataGridTextColumn> 
      </DataGrid.Columns> 
     </DataGrid> 
    </Grid> 
</Window> 
関連する問題