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
精彩评论