How to check that text is changed?

I am just start to learn WPF and have a questions:

My DataContext is some XElement with attribute str, in markup I added:

        <TextBox x:Name="NumStr" HorizontalAlignment="Left" Height="23" Margin="10,257,0,0" TextWrapping="Wrap" Text="{Binding Path = Attribute[str].Value}" VerticalAlignment="Top" Width="120"/>

Now if text in NumStr is changed I want to create some code:

if (element.Attribute("str")?.Value != NumStr.Text && NumStr.Text != "")
                ContentFormControl.AddNumStr(fullPath, NumStr.Text);

But text in element.Attribute("str")?.Value change at the same time with NumStr.Text. How I can correctly check, that text is change. Create other variable I won't.

Thanks for answers, and sorry for my english.

Upvotes: 0

Views: 84

Answers (1)

Alberto
Alberto

Reputation: 15951

Change the Text property binding to OneWay:

Text="{Binding Path=Attribute[str].Value, Mode=OneWay}"

in this way the source property will not be updated every time you change the TextBox's text

Upvotes: 2

Related Questions