【发布时间】:2025-12-21 04:25:11
【问题描述】:
我有一个绑定到某个 ObservableCollection 的树视图,其中填充了一些异步函数。问题是在异步命令工作并更新源集合(添加了一些子节点或类似的东西)之后,它没有在 UI 上更新。我的 XAML 如下所示:
<StackPanel>
<StackPanel.Resources>
<HierarchicalDataTemplate x:Key="CheckBoxItemTemplate"
ItemsSource="{Binding Children, Mode=TwoWay}">
<StackPanel Orientation="Horizontal">
<CheckBox Focusable="False" IsChecked="{Binding IsChecked, Mode=TwoWay}"
VerticalAlignment="Center" />
<ContentPresenter Content="{Binding Node.Caption, Mode=OneWay}" />
</StackPanel>
</HierarchicalDataTemplate>
</StackPanel.Resources>
<TreeView Style="{DynamicResource FormItem}" ItemsSource="{Binding Nodes, Mode=TwoWay}"
ItemTemplate="{StaticResource CheckBoxItemTemplate}" >
</TreeView>
</StackPanel>
有什么建议吗?
【问题讨论】:
-
如何更新收藏?你添加了什么类型的元素?
-
我刚刚用线程窗口调试了它。通过我的异步命令在分离的线程中更新集合,然后在主线程中更新 UI(涉及 RaisePropertyChanged),但 UI 上没有更改...我有一个类 FilingPathTreeNode,其中包含 FilingPathTreeNode 的 ObservableCollection对象。通过我得到的调试,该集合已正确更新。但我在 UI 上看不到任何变化。相同,但同步命令给了我预期的结果......