I have user control with the following parameters:
<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 UserControl, where I declare my user control, I have XAML like this:
<my:SampleBox SampleValue="{Binding SampleValue, Mode=TwoWay}" />
and ViewModel:
public string SampleValue
{
get
{
return this.sampleValue;
}
set
{
this.sampleValue = value;
}
}
I am not interested in INotifyPropertyChanged on the VM (so don’t tell me about it :)) Now it works while the text is displayed in the text box, as I installed it in the VM. But when I change this text, it does not turn into a virtual machine.
What should I do? Think I need to write code inside a user control? Should I deal with TextBox PART and catch LostFocus? Or how does this work with TemplateBinding?
source
share