Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/regex/16.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/html/82.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
wpftreeview。无更新_Wpf_Treeview - Fatal编程技术网

wpftreeview。无更新

wpftreeview。无更新,wpf,treeview,Wpf,Treeview,我有一个绑定到某个ObservableCollection的树视图,其中填充了一些异步函数。问题是,在异步命令工作并更新源集合(添加了一些子节点或类似的内容)之后,它没有在UI上得到更新。我的XAML如下所示: <StackPanel> <StackPanel.Resources> <HierarchicalDataTemplate x:Key="CheckBoxItemTemplate" ItemsSource="{

我有一个绑定到某个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吗?

抱歉打扰你们了,伙计们。这是我的一个愚蠢的错误。我只是没有设置一个控件和使用此控件的窗口的DataContext。结果证明它们有不同的上下文,因为我的ViewModel不是单例。我应该更加小心。

你是如何更新收藏的?您添加了什么类型的元素?我刚刚用Threads窗口调试了它。我的异步命令在分离的线程中更新集合,然后在主线程中更新UI(涉及RaisePropertyChanged),但UI上没有任何更改。。。我有一个类FilingPathTreeNode,它包含FilingPathTreeNode对象的ObservableCollection。通过调试,确保集合正确更新。但我看不到UI上有任何变化。同样的,但同步命令给了我预期的结果…那么您确定要在UI线程上绑定数据吗?只想确认您正在设置使用Dispatcher的数据上下文吗?