Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/wpf/14.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
在WPF 4.0中强制重新加载_Wpf_Behavior_Repaint - Fatal编程技术网

在WPF 4.0中强制重新加载

在WPF 4.0中强制重新加载,wpf,behavior,repaint,Wpf,Behavior,Repaint,我试图使用此代码在处理开始之前强制绘制进度视图: public static class ProgressBehaviors { public static readonly DependencyProperty ForceRepaintProperty = DependencyProperty.RegisterAttached( "ForceRepaint", typeof(bool), typeof(ProgressBe

我试图使用此代码在处理开始之前强制绘制进度视图:

public static class ProgressBehaviors
{
    public static readonly DependencyProperty ForceRepaintProperty =
        DependencyProperty.RegisterAttached(
        "ForceRepaint",
        typeof(bool),
        typeof(ProgressBehaviors),
        new UIPropertyMetadata(false, OnForceRepaintChanged));

    public static bool GetForceRepaint(FrameworkElement treeViewItem)
    {
        return (bool)treeViewItem.GetValue(ForceRepaintProperty);
    }

    public static void SetForceRepaint(FrameworkElement treeViewItem, bool value)
    {
        treeViewItem.SetValue(ForceRepaintProperty, value);
    }

    static void OnForceRepaintChanged(DependencyObject a_object, DependencyPropertyChangedEventArgs e)
    {
        Border item = a_object as Border;
        if (item == null)
            return;

        item.IsVisibleChanged += (s, ev) =>
            {
                item.UpdateLayout();
                Window window = Window.GetWindow(item);
                if (window != null)
                    window.Measure(window.RenderSize);
            };
    }
}

基本行为注入。我必须这样做的原因是,否则,请等待进度消息不会显示,直到完成它必须执行的操作之后。我正在尝试
UpdateLayout
Measure
,但两者都不起作用。每个人都告诉我,我在WPF里做错了事情。什么,我应该在第二个线程或调度程序调用中包装我正在执行的每个进程吗?那看起来很难看

这里有一种方法:

不幸的是,您不能在UI线程上执行繁重的处理,同时拥有一个响应的UI,因为UI线程将很忙。不过,您可以为每个
窗口
创建一个专用的UI线程,因此理论上,我认为您可以使用
WindowStyle=“None”
等创建一个新的“请稍候”-
窗口,它有自己的专用UI线程。不过,我从未尝试过@梅莱克,我只想让进展尽可能简单地表现出来。