开发者

simple binding problem

I have a rather simple problem, but I am unable to get my head around it... I have a class that inherits from UserControl. It has an AxisColor DependencyProperty of type Color. In the XAML structure of the class I have <ms3DTools:ScreenSpaceLines3D Thickness="2" Points="0,0,0 10开发者_JS百科0,0,0" Color="{Binding Mode=OneWay, Path=AxisColor}". The binding does not work. What am I doing wrong?


If you have a UserControl that needs to get a Property AxisColor from a class, you need to set your DataContext of that UserControl to the class that contains AxisColor.

myUserControl.DataContext = myClassInstance;

Otherwise, your user control does not know where to grab the property from.


You probably want to add RelativeSource={RelativeSource Self} to the binding expression. Otherwise, you are binding to the DataContext property.


If you want UI binding then you have to specify ElementName, more options here. If you want data binding then make sure you have DataContext set up correctly.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜