2016-09-13 2 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> 

내가 얻는 오류는 '속성'콘텐츠 '를 한 번만 설정할 수 있습니다.'입니다.

도움이 될 것입니다.

답변

0

DataGridTextColumn에서 Binding 대신 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> 
관련 문제