添加/启用装饰器后如何刷新/更新wpf窗口 [英] How to refresh / update the wpf window after adorner has been added / enabled

查看:202
本文介绍了添加/启用装饰器后如何刷新/更新wpf窗口的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我与WPF的崇拜者有一些麻烦。我的装饰师还可以,但是在我想要的那一刻我没有显示它。

I am having some troubles with the Adorner of WPF. My adorner is ok, but I don't get it displayed at the very moment I want to.

我喜欢做类似的事情:

    public void MyAction()
    {
        // property bound to the adorner VisibiltyProperty
        // I like the happen a refresh now
        // (code is wired correct, if I finish method here, the adorner is drawn)
        this.IsAdornerEnabled = true;

        try
        {
           ... doing some long lasting things I cannot do async cause it depends on a lot of objects owned by main thread...
        }
        finally
        {
            // I like the adorner to be removed from UI now
            this.IsAdornerEnabled = false;
        }
    }

IsAdornerEnabled属性正确绑定到装饰者上,并使得通知。但是在这段代码中,当方法终止时,装饰器被绘制并移除了一秒钟。

The IsAdornerEnabled Property is correct bound to the adorner and makes a notification to it. But in this code the adorner is painted and removed for a split second when the method terminates.

如何在阻止线程被UI之前渲染它?

How is it possible to get it rendered before the UI is thread is blocked?

任何帮助都非常感谢。

说明:
我喜欢使用装饰器来创建我的主标签上方一个不可点击的半透明窗格,上面带有诸如正在加载模块之类的文字。当我的MainThread使用magellan导航,使用Castle解决依赖关系,然后创建一组DevExpress控件时,我喜欢显示此窗格。然后,我再次将其删除。我可以创建装饰器,没问题。装饰器在我的原型项目中工作,在这里我不做任何其他事情。

Explanation: I like to use the adorner to create a non-clickable, half transparent pane over my main tab with a text like "loading module" on it. While my MainThread is navigating with magellan, resolving dependencies with castle and then creating a lof of DevExpress controls, I like to show this pane. Then I remove it again. I can create the adorner, that's no problem. The adorner works in my prototyping project, where I don't do any other things.

推荐答案

我找到了答案的解决方案。

I found the solution for my answer. It might no be the ultra clean way, but it works for me.

ViewModel:

ViewModel:

    private void LoadUi()
    {
        try
        {
            this.IsAdornerVisible = true;
            RefreshCallback();

            ... some long going view initialization...
        }
        finally
        {
            this.IsAdornerVisible = false;
        }
}

RefreshCallback是action类型的属性,由a设置xaml后面的代码中的方法。设置为RefreshCallback的方法是这样的:

RefreshCallback is a property of type action, set by a method in code behind of the xaml. The method set to the RefreshCallback is this one:

    private void Refresh()
    {
        this.Dispatcher.Invoke(new Action(() => { }), DispatcherPriority.ContextIdle, null);
    }

使用ContextIdle在调度程序上的调用使渲染完成在执行空操作之前。使用ContextIdle效果很好。在尝试DispatcherPriority的其他值之前,例如Render。不工作。现在,我很高兴它能正常工作,并且周末可以开始。

The invoke on the dispatcher with ContextIdle makes that the rendering is done before the empty action is executed. With ContextIdle this works good. Before I tried other values of DispatcherPriority, for example Render. Did not work. Now I'm happy it works and weekend can begin.

在这里找到的解决方案:
我的解决方案的来源:现在更新WPF UI:如何等待渲染完成

The solution I found here: Source of my solution: Update the WPF UI now: how to wait for the rendering to finish

这篇关于添加/启用装饰器后如何刷新/更新wpf窗口的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆