How to detect data binding completed in WPF

2019-04-04 07:13发布

When I select an item on my treeview, there is a notable time gap from my viewmodel class being instantiated to the view refreshing and the treeview node being hi-lit.

I need to show a wait cursor during this time - I've tried wrapping the code that instantiates my viewmodel class, but the cursor is back to an arrow a couple of seconds before the whole data binding seems to finish and the node gets hi-lit. Is there some event that tells me when the binding is finished, or when the node is hi-lit ?

This is nothing to do with expanding nodes, simply selecting top-level nodes.

Thanks for any help.

4条回答
霸刀☆藐视天下
2楼-- · 2019-04-04 07:31

You can override the OnContentRendered for Window control.

查看更多
家丑人穷心不美
3楼-- · 2019-04-04 07:36

Is there a "hang" when this gap occurs? Maybe you need to put the heavy logic on a separate thread or simply use IsAsync property of the Binding class. You may also want to take a look at Priority Binding. Here is a pretty good article on how to use it.

查看更多
狗以群分
4楼-- · 2019-04-04 07:46

The Loaded event on the desired TreeView control will happen after all of the bindings have been set up. I think it happens before everything has been drawn though so it might not be exactly what you need.

查看更多
forever°为你锁心
5楼-- · 2019-04-04 07:55

You can get notified when the target or when the source is updated.

<TreeViewItem>
    <TextBlock Name="NameText"
      Text="{Binding Path=Name, Mode=OneWay, NotifyOnTargetUpdated=True}"
      TargetUpdated="OnTargetUpdated"/>
</TreeViewItem>
查看更多
登录 后发表回答