【问题标题】:WPF: How do I style a column in a ListViewWPF:如何在 ListView 中设置列​​的样式
【发布时间】:2010-02-05 02:19:52
【问题描述】:

好的,这就是我目前所拥有的:

<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,我仍然只能得到纯文本。

【问题讨论】:

    标签: wpf xaml listview styles


    【解决方案1】:

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

    【讨论】:

    • 我只是绑定到定义为“
    【解决方案2】:

    呃。同一列不能有 DisplayMemberBinding 和 CellTemplate。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2017-11-29
      • 1970-01-01
      • 2014-06-13
      • 1970-01-01
      • 2014-09-28
      • 2013-11-26
      • 2014-11-11
      • 1970-01-01
      相关资源
      最近更新 更多