It's late and the answer is probably something simple so apologies if this is a dumb question.
I have a user control, it had a single dependency property which is set via a binding which works fine.
I then added two more but the new two (which are setup exactly the same as the first) will not populate from XAML. They always contain their default values (null/0.0).
User control:
public partial class MyUserControl : UserControl
{
public static readonly DependencyProperty WorkingValueProperty;
public static readonly DependencyProperty VarBValueProperty;
public static readonly DependencyProperty VarCValueProperty;
public MyUserControl()
{
InitializeComponent();
}
static MyUserControl()
{
FrameworkPropertyMetadata WorkingValueMetadata = new FrameworkPropertyMetadata(new PropertyChangedCallback(WorkingValuePropertyChanged));
FrameworkPropertyMetadata VarBValueMetadata = new FrameworkPropertyMetadata();
FrameworkPropertyMetadata VarCValueMetadata = new FrameworkPropertyMetadata();
MyUserControl.WorkingValueProperty = DependencyProperty.Register("WorkingValue", typeof(double), typeof(MyUserControl), WorkingValueMetadata);
MyUserControl.VarBValueProperty = DependencyProperty.Register("VarBValue", typeof(double), typeof(MyUserControl), VarBValueMetadata);
MyUserControl.VarCValueProperty = DependencyProperty.Register("VarCValue", typeof(string), typeof(MyUserControl), VarCValueMetadata);
}
public double WorkingValue
{
get
{
return (double)GetValue(WorkingValueProperty);
}
set
{
SetValue(WorkingValueProperty, value);
}
}
public double VarBValue
{
get
{
return (double)GetValue(VarBValueProperty);
}
set
{
SetValue(VarBValueProperty, value);
}
}
public string VarCValue
{
get
{
return (string)GetValue(VarCValueProperty);
}
set
{
SetValue(VarCValueProperty, value);
}
}
private static void WorkingValuePropertyChanged(DependencyObject o, DependencyPropertyChangedEventArgs e)
{
MyUserControl myUC = (MyUserControl)o;
...
}
XAML:
<ic:myusercontrol workingvalue="{Binding AnotherValue, UpdateSourceTrigger=PropertyChanged}" varcvalue="Binding AnotherValue, UpdateSourceTrigger=PropertyChanged}" xmlns:ic="#unknown">
VarBValue="200"/></ic:myusercontrol>
The user control is in a DataTemplate which is used in a listbox. It's not really meant to be bound to the same value as the first field but I know for sure that one works as it's populating the first property fine. If I create the control and just hard code the value all the properties populate fine so it's something to do with it being in a list but I can't figure it out.
I'm looking at the values in call back WorkingValuePropertyChanged (it's there for another purpose but it seemed a reasonable place to check). WorkingValueProperty is populated and the other two are null and 0.0 respectively.
Thanks in advance.
Bob