【问题标题】:WPF ListView using both ItemTemplate and GridViewColumn.. is it possible?WPF ListView 同时使用 ItemTemplate 和 GridViewColumn .. 有可能吗?
【发布时间】:2013-05-31 07:27:39
【问题描述】:

我有一个要求,我有一个通过使用 GridViewColumn 绑定到集合的列表视图。但是我有一个要求,根据列中的某些选定值,我修改列表视图的项目模板。

意味着列表视图只有一行,项目模板应该被修改。有没有可能。

<Window x:Class="ListViewSample.MainWindow"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:local="clr-namespace:ListViewSample"
    Title="MainWindow" Height="350" Width="525"
    >
<Window.Resources>
    <local:ListViewConverter x:Key="listViewConverter"/>
    <DataTemplate x:Key="doubleRowListViewItem">
        <Grid>                
            <Grid.RowDefinitions>
                <RowDefinition Height="Auto"/>
                <RowDefinition Height="Auto"/>
            </Grid.RowDefinitions>
            <TextBlock Background="YellowGreen" Grid.Row="0" Grid.Column="0"/>
            <TextBlock Background="GreenYellow" Grid.Row="1" Grid.Column="0" />                
        </Grid>
    </DataTemplate>
</Window.Resources>
<Grid>
    <Grid.RowDefinitions>
        <RowDefinition Height="Auto"/>
        <RowDefinition Height="*"/>
    </Grid.RowDefinitions>
    <ListView Grid.Row="1" ItemsSource="{Binding Persons}" >            
        <ListView.View>
            <GridView>                    
                <GridViewColumn Header="Country" DisplayMemberBinding="{Binding Country}"/>
                <GridViewColumn Header="Name" DisplayMemberBinding="{Binding Name}"/>
            </GridView>
        </ListView.View>
    </ListView>
</Grid>
</Window>

一旦将国家/地区的值设置为特定条目,项目模板应相应更改。项目模板应设置为上面声明的数据模板。

有什么办法可以做到这一点。

谢谢。 桑迪普

【问题讨论】:

标签: c# .net wpf listview


【解决方案1】:

不确定您在寻找什么,但如果您想要一个视觉动态行,您可以删除DisplayMemberBinding 并使用CellTemplate。您可以像使用任何其他模板一样通过触发器修改该 CellTemplate 或多个 CellTemplate。

【讨论】:

    猜你喜欢
    • 2011-06-11
    • 1970-01-01
    • 2016-09-23
    • 1970-01-01
    • 1970-01-01
    • 2016-03-29
    • 2010-11-26
    • 1970-01-01
    相关资源
    最近更新 更多