Answer the question
In order to leave comments, you need to log in
Why doesn't the source update the value of the destination in WPF?
I'm learning WPF, and specifically the topic of "bindings", and decided to put them into practice. I tried to implement the following example:
Let there be a Phone class (as you can see, dependency properties are not used)
public class Phone
{
public string Title { get; set; }
public int Price { get; set; }
}
<Window.Resources>
<local:Phone Title="Xiaomi" Price="10000" x:Key="myPhone"/>
</Window.Resources>
<TextBlock Grid.Column="0" Grid.Row="0" Text="Модель:"/>
<TextBlock Grid.Column="1" Grid.Row="0" Text="Цена:"/>
<TextBox Grid.Column="0" Grid.Row="1" Text="{Binding Source={StaticResource myPhone}, Path=Title, Mode=TwoWay}" />
<TextBox Grid.Column="1" Grid.Row="1" Text="{Binding Source={StaticResource myPhone}, Path=Price, Mode=TwoWay}" />
<Button Content="Вывести текущие значения" Click="Button_Click_1" />
<Button Content="Изменить значение класса " Click="Button_Click_2" />
private void Button_Click_1(object sender, RoutedEventArgs e)
{
Phone phone = (Phone)this.Resources["myPhone"];
MessageBox.Show($"Модель: {phone.Title}; Стоимоть: {phone.Price}");
}
private void Button_Click_2(object sender, RoutedEventArgs e)
{
Phone phone = (Phone)this.Resources["myPhone"];
phone.Title = "iphone 6s";
phone.Price = 50000;
}
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question