开发者

Forcing rerender in WPF 4.0

开发者 https://www.devze.com 2023-02-08 10:06 出处:网络
I\'m trying to use this code to force my progress view to paint before processing begins: public static class ProgressBehaviors

I'm trying to use this code to force my progress view to paint before processing begins:

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);
            };
    }
}

Basic behavior injection. The reason i have to do this is because otherwise the please wait progress message is not shown until after its done doing whatever it has to do. I'm trying UpdateLayout and Measure and neither works. Everybody tells me that I'm doing things wrong in WPF. What, am I supposed to wrap every process I'm doing in a second thread or a Dispatcher invoke? That seems ugly.


Here is a way: http://dedjo.blogspot.com/2007/08/how-to-doevents-in-wpf.html

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号