Advertisement
Guest User

Untitled

a guest
Jul 13th, 2014
168
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.59 KB | None | 0 0
  1. <Window x:Class="MySimpleProgram.MainWindow"
  2. xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
  3. xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
  4. Title="MainWindow" Height="350" Width="725"
  5. >
  6. <StackPanel Name="StackPanel1" Orientation="Horizontal">
  7.  
  8. <TextBox Name="TextBox2" Text="{Binding Path=FirstName, Mode=TwoWay}" Height="23"/>
  9.  
  10. <Button Name="Button1" Content="Change C# obj people[0]" Width="175" Height="20" Click="Button1_Click" />
  11.  
  12. <ListBox Name="listPeople" DisplayMemberPath="FirstName"/>
  13.  
  14. </StackPanel>
  15. </Window>
  16.  
  17. public class Person : INotifyPropertyChanged
  18. {
  19. public event PropertyChangedEventHandler PropertyChanged;
  20. private String _FirstName;
  21.  
  22. public string FirstName
  23. {
  24. get { return _FirstName; }
  25. set
  26. {
  27. _FirstName = value;
  28. if (PropertyChanged != null)
  29. PropertyChanged(
  30. this, new PropertyChangedEventArgs("FirstName"));
  31. }
  32. }
  33.  
  34. public int Age { get; set; }
  35. }
  36.  
  37. public partial class MainWindow : Window
  38. {
  39. public Person[] people;
  40.  
  41. public MainWindow()
  42. {
  43. InitializeComponent();
  44.  
  45. people = new Person[]{
  46. new Person{ FirstName = "Shirley", Age = 22 },
  47. new Person{ FirstName = "Roy", Age = 29 },
  48. new Person{ FirstName = "Manuel", Age = 34 } };
  49.  
  50. StackPanel1.DataContext = people[0];
  51.  
  52. listPeople.ItemsSource = people;
  53. }
  54.  
  55.  
  56. private void Button1_Click(object sender, RoutedEventArgs e)
  57. {
  58. people[0].FirstName += "y";
  59. }
  60.  
  61. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement