I have custom control with following:
<TextBox Grid.Column="3" Text="{TemplateBinding SampleValue}" />
public static readonly DependencyProperty SampleValueProperty =
DependencyProperty.RegisterAttached("SampleValue", typeof(string), typeof(IdattFilterBox), new PropertyMetadata(null));
public string SampleValue
{
get { return GetValue(SampleValueProperty) as string; }
set { this.SetValue(SampleValueProperty, value); }
}
In a UserControl where I declare my custom control I have XAML like this:
<my:SampleBox SampleValue="{Binding SampleValue, Mode=TwoWay}" />
and ViewModel like so:
public string SampleValue
{
get
{
return this.sampleValue;
}
set
{
this.sampleValue = value;
}
}
I don't care about INotifyPropertyChanged on VM (so don't tell me about it :) ) Right now it's working as far as displaying text in text box just like I set it in VM. But when I modify this text - it doesn't get bubbled up back into VM.
What should I do? I guess I have to write some code inside custom control? Should I deal with TextBox PART and catch LostFocus? Or how does it work with TemplateBinding?
TemplateBinding
is only OneWay
.
If you are using Silverlight 4, you can try this,
{Binding SampleValue, Mode=TwoWay, RelativeSource={RelativeSource TemplatedParent}}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With