我有一个带有可观察集合源的列表视图。我确信数据在代码中有所改变,但我完全厌倦了为什么UI不会显示更改。我错过了什么?
我的xaml:
<GridViewColumn Width="70" Header="Status">
<GridViewColumn.CellTemplate>
<DataTemplate>
<!--<CheckBox IsChecked="{Binding Path=Status, Mode= Twoway}" HorizontalContentAlignment="Center" IsEnabled="False"/>-->
<TextBlock Text="{Binding Path=Status, Mode= Twoway}" TextAlignment="Center" Loaded="Page_Loaded"/>
</DataTemplate>
</GridViewColumn.CellTemplate>
</GridViewColumn>
我的课程:
public partial class tblADRMaster: INotifyPropertyChanged
{
public string Status
{
get { return _status; }
set
{
if (_status != value)
{
_status = value;
OnPropertyChanged("Status");
}
}
}
}
这是我背后的代码:
ObservableCollection<tblADRMaster> list = new ObservableCollection<tblADRMaster>();
CurrentCase = FileMaintenanceBusiness.Instance.GetADRMasterInfobyKeywordRefresh(caseNo.CaseIDSystem, "CaseIDSystem");
foreach (var c in listFrWWC)
{
if (c.CaseIDSystem != CurrentCase.CaseIDSystem)
list.Add(c);
else
list.Add(CurrentCase);
}
foreach (var caseMaster in list)
{
caseMaster.IsMissingDocs = GetMissingDoc(caseMaster.tblADRDispositions);
caseMaster.IsProblemCase = !string.IsNullOrEmpty(caseMaster.ProblemNote) ? "Yes" : "No";
caseMaster.Status = GetStatus(caseMaster);
}
lvAdrMaster.ItemsSource = list;
我想改变状态。它确实改变了因为我放置了断点并且STATUS从HOLD变为ACTIVE但是listview不会显示更改。它保持HOLD,除非我按回btn或重新加载项目。
我整天都在排除故障,我似乎无法想到任何我可能错过的事情。请告诉我。感谢。
答案 0 :(得分:1)
尝试使用此文本块绑定:
Text="{Binding Path=Status, Mode= Twoway, UpdateSourceTrigger=PropertyChanged}"
答案 1 :(得分:1)
尝试使用 CollecitonViewSource
private ListCollectionView EmpCollectionView
{
get
{
return (ListCollectionView)CollectionViewSource.GetDefaultView(ListOfEmp);
}
}
private ObservableCollection<Employee> listOfEmp = new ObservableCollection<Employee>();
public ObservableCollection<Employee> ListOfEmp
{
get { return listOfEmp; }
set { listOfEmp = value; }
}
并在更新集合后刷新collectionViewSource 像
public void OnAdd(object sender)
{
ToggleButton tb = sender as ToggleButton;
EmpCollectionView.SortDescriptions.Clear();
if (tb.IsChecked == true)
{
EmpCollectionView.SortDescriptions.Add(new SortDescription(tb.Content.ToString(), ListSortDirection.Ascending));
EmpCollectionView.Refresh();
}
else
{
EmpCollectionView.SortDescriptions.Add(new SortDescription(tb.Content.ToString(), ListSortDirection.Descending));
EmpCollectionView.Refresh();
}
}
答案 2 :(得分:0)
您是否在INotifyPropertyChanged
类中实施了tblADRMaster
接口并提出了Status
属性的属性通知?