admin管理员组文章数量:1353119
I have a StoreViewModel, which implements INotifyPropertyChanged
. And a property in it:
public ObservableCollection<ItemModel> ItemsCollection
{
get => _itemsCollection;
set => SetProperty(ref _itemsCollection, value);
}
I want to hide certain items from being displayed in a ListView, if ItemModel.IsAvailable property is False. I know it should be with ItemContainerStyle
, something like this:
<ListView.ItemContainerStyle>
<Style TargetType="ListViewItem">
<interactivity:Interaction.Behaviors>
<core:DataTriggerBehavior
Binding="{Binding RelativeSource={ ... }, Path=Content.IsAvailable , Mode=OneWay}"
Value="False">
<core:ChangePropertyAction
PropertyName="Visibility"
Value="Collapsed" />
</core:DataTriggerBehavior>
</interactivity:Interaction.Behaviors>
</Style>
</ListView.ItemContainerStyle>
What should be the RelativeSource
? I know how to do it in WPF
, but not in UWP
I have a StoreViewModel, which implements INotifyPropertyChanged
. And a property in it:
public ObservableCollection<ItemModel> ItemsCollection
{
get => _itemsCollection;
set => SetProperty(ref _itemsCollection, value);
}
I want to hide certain items from being displayed in a ListView, if ItemModel.IsAvailable property is False. I know it should be with ItemContainerStyle
, something like this:
<ListView.ItemContainerStyle>
<Style TargetType="ListViewItem">
<interactivity:Interaction.Behaviors>
<core:DataTriggerBehavior
Binding="{Binding RelativeSource={ ... }, Path=Content.IsAvailable , Mode=OneWay}"
Value="False">
<core:ChangePropertyAction
PropertyName="Visibility"
Value="Collapsed" />
</core:DataTriggerBehavior>
</interactivity:Interaction.Behaviors>
</Style>
</ListView.ItemContainerStyle>
What should be the RelativeSource
? I know how to do it in WPF
, but not in UWP
1 Answer
Reset to default 0Since you are using MVVM, maybe solve this in another way. You could try to change the data source in the ViewModel
instead of handing this in the view level. You could just pass a list which doesn't contains the item you want to show to the ListView
as data source.
Something like this:
newList = new ObservableCollection<ItemModel>(ItemsCollection.Where(x => x.IsAvailable == true).ToList());
In this way, you don't need to change the XAML but just show it as you've already handled the data in your ViewModel.
本文标签: xamlHow to hide a ListView item in UWP depending on item39s propertyStack Overflow
版权声明:本文标题:xaml - How to hide a ListView item in UWP depending on item's property - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1743924768a2562757.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
RelativeSource Self
, and could you please provide the relevant code of Listview so that we can better solve the problem for you? – Junjie Zhu - MSFT Commented Apr 1 at 3:15LIstView
. – Roy Li - MSFT Commented 2 days ago