Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <Window x:Class="MySimpleProgram.MainWindow"
- xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
- xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
- Title="MainWindow" Height="350" Width="725"
- >
- <StackPanel Name="StackPanel1" Orientation="Horizontal">
- <TextBox Name="TextBox2" Text="{Binding Path=FirstName, Mode=TwoWay}" Height="23"/>
- <Button Name="Button1" Content="Change C# obj people[0]" Width="175" Height="20" Click="Button1_Click" />
- <ListBox Name="listPeople" DisplayMemberPath="FirstName"/>
- </StackPanel>
- </Window>
- public class Person : INotifyPropertyChanged
- {
- public event PropertyChangedEventHandler PropertyChanged;
- private String _FirstName;
- public string FirstName
- {
- get { return _FirstName; }
- set
- {
- _FirstName = value;
- if (PropertyChanged != null)
- PropertyChanged(
- this, new PropertyChangedEventArgs("FirstName"));
- }
- }
- public int Age { get; set; }
- }
- public partial class MainWindow : Window
- {
- public Person[] people;
- public MainWindow()
- {
- InitializeComponent();
- people = new Person[]{
- new Person{ FirstName = "Shirley", Age = 22 },
- new Person{ FirstName = "Roy", Age = 29 },
- new Person{ FirstName = "Manuel", Age = 34 } };
- StackPanel1.DataContext = people[0];
- listPeople.ItemsSource = people;
- }
- private void Button1_Click(object sender, RoutedEventArgs e)
- {
- people[0].FirstName += "y";
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement