WPF and AutoRedraw
I have a custom WPF Line and its style. UserControl Resources:
<!-- Framework properties to update -->
<SolidColorBrush x:Key="MyLineBrush" Color="LightGreen" />
<sys:Double x:Key="MyLineStrokeThickness">1</sys:Double>
<!-- Custom property to update -->
<sys:Boolean x:Key="MyLineIsArrowUsed">false</sys:Boolean>
<Style TargetType="local:MyLine" x:Key="MyLineStyleKey">
<!-- AutoUpdates the control -->
<Setter Property="Fill"
Value="{DynamicResource MyLineBrush}"/>
<Setter Property="StrokeThickness"
Value="{DynamicResource MyLineStrokeThickness}" />
<!-- does NOT AutoUpdate the control -->
<Setter Property="ShowText"
Value="{开发者_JAVA百科DynamicResource MyLineIsArrowUsed}"/>
Now, I observed when I update the MyLineStrokeThickness
the control is updated instantly.
but when I update my custom dependency property MyLineIsArrowUsed
there are no changes.
What should I use in order to update the custom control (line) drawing once my custom dependency property is updated?
I tried:
static void OnIsArrowUsedChanged(DependencyObject source, DependencyPropertyChangedEventArgs e)
{
var s = (MyLine)source;
s.UpdateLayout();
}
but this does not work.
The control updates only when I move it or do other actions when it is forced to redraw itself.
In the dependency property declaration add FrameworkPropertyMetadata.AffectsMeasure
http://msdn.microsoft.com/en-us/library/system.windows.frameworkpropertymetadata.affectsmeasure.aspx
精彩评论