Guest User

Untitled

a guest
Jul 21st, 2018
74
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.40 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading.Tasks;
  6. using System.Windows;
  7. using System.Windows.Controls;
  8. using System.Windows.Data;
  9. using System.Windows.Documents;
  10. using System.Windows.Input;
  11. using System.Windows.Media;
  12. using System.Windows.Media.Imaging;
  13. using System.Windows.Navigation;
  14. using System.Windows.Shapes;
  15.  
  16. namespace DataContextDemo
  17. {
  18. /// <summary>
  19. /// Interaktionslogik für MainWindow.xaml
  20. /// </summary>
  21. public partial class MainWindow : Window
  22. {
  23. Person obj = new Person()
  24. {
  25. FirstName = "John",
  26. LastName = "Smith",
  27. Age = 30
  28. };
  29.  
  30.  
  31.  
  32. public MainWindow()
  33. {
  34.  
  35. InitializeComponent();
  36.  
  37.  
  38.  
  39. this.DataContext = obj;
  40. }
  41.  
  42.  
  43. }
  44. }
  45.  
  46. <Window x:Class="DataContextDemo.MainWindow"
  47. xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
  48. xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
  49. xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
  50. xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
  51. xmlns:local="clr-namespace:DataContextDemo"
  52. mc:Ignorable="d"
  53. Title="MainWindow" Height="350" Width="525">
  54. <Grid>
  55. <Grid.ColumnDefinitions>
  56. <ColumnDefinition Width="80"/>
  57. <ColumnDefinition Width="*"/>
  58. </Grid.ColumnDefinitions>
  59.  
  60. <Grid.RowDefinitions>
  61. <RowDefinition Height="30"/>
  62. <RowDefinition Height="30"/>
  63. <RowDefinition Height="30"/>
  64. </Grid.RowDefinitions>
  65.  
  66. <TextBlock Margin="4" Text="First Name" VerticalAlignment="Center"/>
  67. <TextBox Margin="4" Text="{Binding Path= FirstName}" Grid.Column="1"/>
  68.  
  69. <TextBlock Margin="4" Text="Last Name" Grid.Row="1" VerticalAlignment="Center"/>
  70. <TextBox Margin="4" Text="{Binding Path= LastName}" Grid.Column="2" Grid.Row="1"/>
  71.  
  72. using System;
  73. using System.Collections.Generic;
  74. using System.ComponentModel;
  75. using System.Linq;
  76. using System.Runtime.CompilerServices;
  77. using System.Text;
  78. using System.Threading.Tasks;
  79.  
  80. namespace DataContextDemo
  81. {
  82. public class Person : INotifyPropertyChanged
  83. {
  84. public event PropertyChangedEventHandler PropertyChanged;
  85.  
  86. public Augen Eyeobj = new Augen("Red");
  87.  
  88.  
  89.  
  90.  
  91. //public PropertyChangedEventHandler handler = PropertyChanged;
  92.  
  93. private void NotifyPropertyChanged([CallerMemberName] String propertyName = "")
  94. {
  95. PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));
  96. }
  97.  
  98.  
  99.  
  100. public string FirstName
  101. {
  102. get
  103. {
  104. return this.firstName;
  105. }
  106. set
  107. {
  108. this.firstName = value;
  109. NotifyPropertyChanged();
  110. }
  111. }
  112.  
  113. public string LastName
  114. {
  115. get
  116. {
  117. return this.lastName;
  118. }
  119. set
  120. {
  121. this.lastName = value;
  122. NotifyPropertyChanged();
  123. }
  124. }
  125.  
  126. public int Age
  127. {
  128. get
  129. {
  130. return this.age;
  131. }
  132. set
  133. {
  134. this.age = value;
  135. NotifyPropertyChanged();
  136. }
  137. }
  138.  
  139. private string firstName { get; set; }
  140. public string lastName { get; set; }
  141. public int age { get; set; }
  142. }
  143. }
  144.  
  145.  
  146.  
  147. <TextBlock Margin="4" Text="Age" Grid.Row="2" VerticalAlignment="Center"/>
  148. <TextBox Margin="4" Text="{Binding Path = Eyeobj.Farbe}" Grid.Column="3" Grid.Row="2"/>
  149.  
  150. <TextBlock Margin="3" Text="{Binding Path=Eyeobj.Farbe}" Grid.Row="2" Grid.Column="3" x:Name="testbox"></TextBlock>
  151.  
  152. <Button Margin="4" Grid.Row="3" Click="Button_Click"></Button>
  153.  
  154.  
  155.  
  156.  
  157.  
  158. </Grid>
  159. </Window>
  160.  
  161. using System;
  162. using System.Collections.Generic;
  163. using System.ComponentModel;
  164. using System.Linq;
  165. using System.Runtime.CompilerServices;
  166. using System.Text;
  167. using System.Threading.Tasks;
  168.  
  169. namespace DataContextDemo
  170. {
  171. public class Augen : INotifyPropertyChanged
  172. {
  173. public event PropertyChangedEventHandler PropertyChanged;
  174.  
  175. public string farbe = "Blau";
  176.  
  177. public Augen(string farbe)
  178. {
  179. Farbe = farbe;
  180. }
  181.  
  182.  
  183. //public PropertyChangedEventHandler handler = PropertyChanged;
  184.  
  185. private void NotifyPropertyChanged([CallerMemberName] String propertyName = "")
  186. {
  187. PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));
  188. }
  189.  
  190. public string Farbe
  191. {
  192. get
  193. {
  194. return this.farbe;
  195. }
  196. set
  197. {
  198. this.farbe = value;
  199. NotifyPropertyChanged();
  200. }
  201. }
  202.  
  203.  
  204. }
  205. }
Add Comment
Please, Sign In to add comment