开发者

Should binding to Path.Data property work?

开发者 https://www.devze.com 2023-03-17 08:31 出处:网络
EDIT: Note! This turned out to be a typo in my code According to msdn , Path.Data appears to be bindable. But I am not sure how to read the Depenedency Property Information part of the msdn page. Is

EDIT: Note! This turned out to be a typo in my code

According to msdn , Path.Data appears to be bindable. But I am not sure how to read the Depenedency Property Information part of the msdn page. Is AffectsRender and AffectsMeasure be enough for my use?

If I use x:Name to directly assign it, the geometry appears

var curve = new GeometryGroup();
curve.Children.Add(new LineGeometry(new Point(0, 0), new Point(20, 20)));
curve.Children.Add(new LineGeometry(new Point(0, 20), new Point(20, 0)));
CurveGraph.Data = curve;

This works fine. Draws a nice "X".

However, if I have a dependency property of type GeometryGroup in the ViewModel

var curve = new GeometryGroup();
curve.Children.Add(new LineGeometry(new Point(0, 0), new Point(20, 20)));
curve.Children.Add(new LineGeometry(new Point(0, 20), new Point(20, 0)));
GeometryData= curve;

dp :

public GeometryGroup GeometryData
开发者_JAVA百科    {
        get { return (GeometryGroup)GetValue(GeometryDataProperty); }
        set { SetValue(GeometryDataProperty, value); }
    }

    public static readonly DependencyProperty GeometryDataProperty =  DependencyProperty.Register("GeometryDataProperty", typeof(GeometryGroup), typeof(MiniTrendVm), new UIPropertyMetadata(new GeometryGroup()));

...then it didn't work. Nothing happens. No "X".

xaml :

<Path Data="{Binding GeometryData}" x:Name="CurveGraph" Stroke = "{Binding StrokeColor}" StrokeThickness = "2" Grid.RowSpan="4"/> 

Should this work? Have I fat fingered something? Or can't the Data property be set this way? The brush was databound in both cases, so I know that the datacontext is correctly set.


Your DependencyProperty is registered as "GeometryDataProperty" which should be "GeometryData". Not quite sure if this actually breaks the binding. Edit: Recent tests by H.B. reveal that this probably is indeed the cause. Binding that property is possible.

0

精彩评论

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

关注公众号