Quantcast
Channel: Windows Presentation Foundation (WPF) forum
Viewing all articles
Browse latest Browse all 18858

Updating Data on Target

$
0
0

Hi all!

I read about Data Binding. Documentation is written that after updating Source Target update automatically. But real updating hasn't occured.

XAML Code:

<Window
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        xmlns:d="http://schemas.microsoft.com/expression/blend/2008" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" mc:Ignorable="d" x:Class="WpfApplication1.MainWindow"
        Title="MainWindow" 
        Height="500" Width="850"
        MinHeight="400" MinWidth="700"
        xml:lang="en-US"
>
    <StackPanel Name="stackPanel"
    xmlns:c="clr-namespace:WpfApplication1">
        <Button Background="{Binding Path=ColorName}" Content="{Binding Path=ColorName}"></Button>
        <Button Name="b" Click="b_Click">Click to make upper button blue</Button>
    </StackPanel>
</Window>


C# Code:

public class MyData {
        public string ColorName {get; set;}

        public MyData (string s) {
            ColorName = s;
        }
    }

    public partial class MainWindow : Window {

        MyData m;

        public MainWindow () {
            m = new MyData ("Red");
            InitializeComponent ();
            stackPanel.DataContext = m;
        }

        private void b_Click (object sender, RoutedEventArgs e) {
            m.ColorName = "Blue";
        }
    }

How can I update Target automatically?

Thanks for help in advance.







Viewing all articles
Browse latest Browse all 18858

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>