0

このコードを使用して、処理が開始される前に進行状況ビューを強制的にペイントしようとしています:

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 で間違ったことをしているとみんなに言われます。2 番目のスレッドまたは Dispatcher 呼び出しで実行しているすべてのプロセスをラップする必要がありますか? それは醜いようです。

4

1 に答える 1

0

方法は次のとおりです:http://dedjo.blogspot.com/2007/08/how-to-doevents-in-wpf.html

于 2011-02-04T21:07:39.920 に答える