2010-02-05 26 views
0

好的作风列,这是我到目前为止有:WPF:如何在一个ListView

<Window x:Class="MainWindow" 
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" 
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" 
    xmlns:sys="clr-namespace:System;assembly=mscorlib" 
    xmlns:s="clr-namespace:System;assembly=mscorlib" 
    Title="MainWindow" 
    Height="350" 
    Width="525"> 
<Window.Resources> 
    <DataTemplate x:Key="CheckboxColumn" 
        DataType="{x:Type sys:Boolean}"> 
     <CheckBox IsChecked="{Binding Path=.}" /> 
    </DataTemplate> 
</Window.Resources> 
<Grid> 
    <Grid.Resources> 
     <x:Array Type="{x:Type s:Boolean}" 
       x:Key="items"> 
      <s:Boolean>False</s:Boolean> 
      <s:Boolean>True</s:Boolean> 
     </x:Array> 
    </Grid.Resources> 
    <ListView ItemsSource="{StaticResource items}"> 
     <ListView.View> 
      <GridView> 
       <GridViewColumn Header="Number" 
           DisplayMemberBinding="{Binding Path=.}" 
           CellTemplate="{StaticResource CheckboxColumn}" /> 

       <GridViewColumn Header="Name" 
           DisplayMemberBinding="{Binding Path=.}" /> 
      </GridView> 
     </ListView.View> 
    </ListView> 
</Grid> 
</Window> 

即使我设置CellTemplate我仍然只得到纯文本。

回答

0

既然您没有发布您绑定的数据类,我无法确定,但看起来您可能会绑定到非布尔类型,并且绑定失败。你看过输出窗口中的绑定异常吗?

+0

我只是绑定到数组定义为“ 2010-02-05 02:33:37

0

Duh。对于同一列,您不能有DisplayMemberBindingCellTemplate