Set dependency property to bind two paths in user control

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?

+5
source share
4

TemplateBinding . Mode=TwoWay

Source={Binding RelativeSource={RelativeSource TemplatedParent}}.

+4

TemplateBinding - OneWay.

Silverlight 4, ,

{Binding SampleValue, Mode=TwoWay, RelativeSource={RelativeSource TemplatedParent}}
+7

, DependencyProperty.Register DependencyProperty.RegisterAttached?

, , , .

, , .

, , , 2

  • INotifyPropertyChanged ( - )

  • PropertyMetadata (null) ( , ) NewValue .

, , , , . ( XAML )

, TextBox , .

+2

Source, , .
- :

<my:SampleBox SampleValue="{Binding SampleValue, Source={StaticResource someViewModel}, Mode=TwoWay}" />
0

All Articles