WPF-根据某些条件设置列表视图的ItemsSource [英] WPF - set the ItemsSource of List View based on some condition

查看:251
本文介绍了WPF-根据某些条件设置列表视图的ItemsSource的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否可以根据某些条件设置列表视图的ItemsSource. 我尝试了以下方法,但是没有用.

Is it possible to set the ItemsSource of a list view based on Some condition. I tried the following, but it didn't work.

   <ListView ItemsSource="{Binding FirstTypeOfSource}"  .....>
        <ItemsControl.ItemContainerStyle>
                <Style >
                    <Style.Triggers>
                        <DataTrigger Binding="{Binding Category}" Value="All">
                            <Setter Property="ItemsSource" Value="SecondTypeOfCategory"/>
                        </DataTrigger>
                    </Style.Triggers>
                </Style>
            </ItemsControl.ItemContainerStyle>
   </ListView>

有人可以帮忙找出解决方案吗?

Can someone help to figure out the solution ?

推荐答案

这应该做到

    <ListView ItemsSource="{Binding FirstTypeOfSource}">
        <ListView.Style>
            <Style TargetType="ListView">
                <Style.Triggers>
                    <DataTrigger Binding="{Binding Category}" Value="All">
                        <Setter Property="ItemsSource" Value="{Binding SecondTypeOfCategory}"/>
                    </DataTrigger>
                </Style.Triggers>
            </Style>
        </ListView.Style>
    </ListView>

这篇关于WPF-根据某些条件设置列表视图的ItemsSource的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆