I'm assuming you're trying mock an E-commerce service.
(我假设您正在尝试模拟电子商务服务。)
So you need to grey out items which are not currently available. (因此,您需要将当前不可用的项目显示为灰色。)
First you need to Have a collection of items in your ViewModel
(首先,您需要在ViewModel中有一组项目)
ObservableCollection<ItemObj> Items{get;set;}
And ItemObj should contain a property IsAvailable , which should be the result of CheckOnline() function.
(ItemObj应该包含属性IsAvailable ,该属性应该是CheckOnline()函数的结果。)
This collection should be bound to the ListBox/ListView you're using.
(此集合应绑定到您正在使用的ListBox / ListView。)
You can use a DataTrigger to write a custom style for Items which return false from CheckOnline()
(您可以使用DataTrigger为从CheckOnline()返回false的Items编写自定义样式)
<DataTrigger Binding="{Binding IsAvailable}" Value="False">
<!-- Write custom style here -->
</DataTrigger>
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…