我将ListView ItemSource设置为List<T>,其中T是我的模型。我正在将这个List<T>的一些属性绑定到XAML中的一些标签。现在,基于一个属性,我想将Label设置为一些文本。
例如,if (Property.IsCompleted == true),我可能希望在ListView的视图单元格中将标签设置为"Done“而不是"True”。
我希望这总结了这个问题。我尝试过其他方法,但都不起作用。
这是我的ListView的项目显示方法:
private void bookingLV_ItemAppearing(object sender, ItemVisibilityEventArgs e)
{
BookingsModel convert = (BookingsModel)e.Item;
var select = convert.IsCompleted;
if(select == true)
{
IsDone = "Completed";
}
IsDone = "Pending";
}我有一个名为IsDone的自定义属性:
public string IsDone { get; set; }这就是我在Xaml中ListView的视图单元格中绑定IsDone的方法
<Label Text="{Binding IsDone}"></Label>我希望能够根据Model对象的属性将Label的Text属性设置为某些文本。
发布于 2019-04-28 03:34:14
在模型中创建一个只读属性,该属性根据另一个属性返回值
public string IsDone
{
get
{
if (select) return "Completed";
return "Pending";
}
}如果您正在使用触发器,则需要确保“INotifyPropertyChanged”属性的设置器为这两个触发器触发PropertyChanged事件
public bool selected {
get {
...
}
set {
...
PropertyChanged("selected");
PropertyChanged("IsDone");
}
}https://stackoverflow.com/questions/55883957
复制相似问题