I've got a custom control ive created that is instanced in my view, in my custom control (a text box) i have a dependency property set up which is bound to the text value, this all works correctly and updates. However I now want to bind a dependency property of my view to the dependency property of my control but I cant get this to quite work. Heres what i mean
Control selected bits
<TextBox x:Name="txtBox"
GotFocus="txtBox_GotFocus"
LostFocus="txtBox_LostFocus"
Grid.Row="0"
Text="{Binding TextValueProperty, Mode=TwoWay}"/>
public DependencyProperty TextValueProperty{ get; set; }
public int TextValue
{
get { return (int)GetValue(TextValueProperty); }
set
{
if ((value >= MinValue) && (value <= MaxValue))
{
SetValue(TextValueProperty, value);
}
}
}
public CustomControl()
{
TextValueProperty = DependencyProperty.Register("TextValueProperty ", typeof(int), typeof(CustomControl), new PropertyMetadata(null ));
}
View selected bits
<my:CustomControl x:Name="TxtBoxInt" Grid.RowSpan="2" Grid.Row="0" Grid.Column="1"/>
I want to do this:
<my:CustomControlx:Name="TxtBoxInt" TextValueProperty="{Binding DestinationProperty}" Grid.RowSpan="2" Grid.Row="0" Grid.Column="1"/>
and Code from view
public DependencyProperty DestionationProperty;
public int Destination
{
get
{
return (int)GetValue(DestionationProperty);
}
set
{
SetValue(DestionationProperty, value);
}
}
public CustomControl()
{
DestionationProperty = DependencyProperty.Register("DestionationProperty", typeof(int), typeof(CustomControl), null);
InitializeComponent();
}
So what do i need to do to be able to bind my int value Destination in my view to have the same value as my TextValue from my custom control? Thanks :)
ps hi ash