WPF:如何在ListView中设置列的样式

WPF:如何在ListView中设置列的样式,wpf,xaml,listview,styles,Wpf,Xaml,Listview,Styles,好的,这就是我到目前为止的情况: <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-

好的,这就是我到目前为止的情况:

<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,我还是得到了纯文本。

由于您没有发布要绑定到的数据类,我无法确定,但您可能绑定到了非布尔类型,绑定失败。您是否查看了绑定异常的输出窗口?

Duh。不能为同一列使用DisplayMemberBinding和CellTemplate。

我刚刚绑定到定义为的数组