更新后列表视图不会改变

发布于 2024-12-11 07:34:00 字数 1761 浏览 0 评论 0原文

我有一个带有可观察集合源的列表视图。我确信数据在后面的代码中发生了变化,但我完全筋疲力尽为什么用户界面不会显示更改。我缺少什么?

我的 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;

我想更改状态。它确实发生了变化,因为我放置了一个断点,并且状态从“保持”变为“活动”,但列表视图不会显示更改。它保持保持状态,除非我按返回按钮或重新加载项目。

我一整天都在解决这个问题,我似乎想不出还有什么我可能错过的事情。请告诉我。谢谢。

I have a listview with observable collection source. I am sure the data changed in code behind but I am totally exhausted why the UI won't display the changes. What am I missing?

My 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>

My class:

public partial class tblADRMaster: INotifyPropertyChanged
{
    public string Status
    {
        get { return _status; }
        set
        {
            if (_status != value)
            {
                _status = value;
                OnPropertyChanged("Status");
            }
        }
    }
}

This is my code behind:

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;

I want to change the status. It does change coz I placed a breakpoint and STATUS went from HOLD to ACTIVE but the listview won't display the change. it remains HOLD, unless I press back btn or reload the items.

I have been troubleshooting this all day and I cannot seem to think of anything else I could have missed. Pls tell me. thanks.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

空城旧梦 2024-12-18 07:34:00

尝试对您的文本块绑定进行此操作:

Text="{Binding Path=Status, Mode= Twoway, UpdateSourceTrigger=PropertyChanged}"

Try this for your textblock binding:

Text="{Binding Path=Status, Mode= Twoway, UpdateSourceTrigger=PropertyChanged}"
北座城市 2024-12-18 07:34:00

尝试使用 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();
        }
    }

Try to use 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; }
    }

and after u update the collection just refresh the collectionViewSource
like

 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();
        }
    }
但可醉心 2024-12-18 07:34:00

您是否在 tblADRMaster 类中实现了 INotifyPropertyChanged 接口并为 Status 属性引发了属性通知?

Have you implemented INotifyPropertyChanged interface in tblADRMaster class and raised property notification for Status property?

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文