tags:

views:

38

answers:

3

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 100,0,0" Color="{Binding Mode=OneWay, Path=AxisColor}". The binding does not work. What am I doing wrong?

A: 

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

Daniel Pratt
Just tried it, but it not work...
licensedlice
A: 

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.

Andrey
A: 

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.

jsmith
Thanks, this worked...One more question: Is there an equivalent for this in XAML?
licensedlice
I guess I'm confused. I thought you said that the 'AxisColor' property was defined on the UserControl class itself. Did you just do 'myUserControl.DataContext = myUserControl;'?
Daniel Pratt
or more simply: MyUserControl.DataContext = this; ?
John Gardner
yes, that's what i did...
licensedlice