应该绑定到Path.Data属性吗? [英] Should binding to Path.Data property work?
问题描述
编辑:注意!这原来是我的代码中的打字错误
根据msdn ,Path.Data似乎是可绑定的。但我不知道如何阅读msdn页面的Depenency Property Information部分。 AffectsRender和AffectsMeasure是否足以使用?
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?
如果我使用x:Name来直接分配,几何出现
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;
这很好。绘制一个不错的X。
This works fine. Draws a nice "X".
但是,如果在ViewModel中有一个类型为GeometryGroup的依赖属性
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
{
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()));
...然后它没有工作。什么都没发生。没有X。
...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"/>
应该这个工作吗?我胖胖了吗?还是不能以这种方式设置Data属性?在这两种情况下,刷子都是数据绑定的,所以我知道数据文本正确设置。
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.
推荐答案
您的 DependencyProperty
注册为GeometryDataProperty
,应为GeometryData
。不太确定这是否真的打破了绑定。 编辑:H.B.最近的测试显示这可能是事实。绑定该属性是可能的。
Your DependencyProperty
is registered as "GeometryDataProperty"
which should be "GeometryData"
. Not quite sure if this actually breaks the binding. Recent tests by H.B. reveal that this probably is indeed the cause. Binding that property is possible.
这篇关于应该绑定到Path.Data属性吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!