Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- using System.Windows;
- using System.Windows.Controls;
- using System.Windows.Data;
- using System.Windows.Documents;
- using System.Windows.Input;
- using System.Windows.Media;
- using System.Windows.Media.Imaging;
- using System.Windows.Navigation;
- using System.Windows.Shapes;
- namespace DataContextDemo
- {
- /// <summary>
- /// Interaktionslogik für MainWindow.xaml
- /// </summary>
- public partial class MainWindow : Window
- {
- Person obj = new Person()
- {
- FirstName = "John",
- LastName = "Smith",
- Age = 30
- };
- public MainWindow()
- {
- InitializeComponent();
- this.DataContext = obj;
- }
- }
- }
- <Window x:Class="DataContextDemo.MainWindow"
- 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"
- xmlns:local="clr-namespace:DataContextDemo"
- mc:Ignorable="d"
- Title="MainWindow" Height="350" Width="525">
- <Grid>
- <Grid.ColumnDefinitions>
- <ColumnDefinition Width="80"/>
- <ColumnDefinition Width="*"/>
- </Grid.ColumnDefinitions>
- <Grid.RowDefinitions>
- <RowDefinition Height="30"/>
- <RowDefinition Height="30"/>
- <RowDefinition Height="30"/>
- </Grid.RowDefinitions>
- <TextBlock Margin="4" Text="First Name" VerticalAlignment="Center"/>
- <TextBox Margin="4" Text="{Binding Path= FirstName}" Grid.Column="1"/>
- <TextBlock Margin="4" Text="Last Name" Grid.Row="1" VerticalAlignment="Center"/>
- <TextBox Margin="4" Text="{Binding Path= LastName}" Grid.Column="2" Grid.Row="1"/>
- using System;
- using System.Collections.Generic;
- using System.ComponentModel;
- using System.Linq;
- using System.Runtime.CompilerServices;
- using System.Text;
- using System.Threading.Tasks;
- namespace DataContextDemo
- {
- public class Person : INotifyPropertyChanged
- {
- public event PropertyChangedEventHandler PropertyChanged;
- public Augen Eyeobj = new Augen("Red");
- //public PropertyChangedEventHandler handler = PropertyChanged;
- private void NotifyPropertyChanged([CallerMemberName] String propertyName = "")
- {
- PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));
- }
- public string FirstName
- {
- get
- {
- return this.firstName;
- }
- set
- {
- this.firstName = value;
- NotifyPropertyChanged();
- }
- }
- public string LastName
- {
- get
- {
- return this.lastName;
- }
- set
- {
- this.lastName = value;
- NotifyPropertyChanged();
- }
- }
- public int Age
- {
- get
- {
- return this.age;
- }
- set
- {
- this.age = value;
- NotifyPropertyChanged();
- }
- }
- private string firstName { get; set; }
- public string lastName { get; set; }
- public int age { get; set; }
- }
- }
- <TextBlock Margin="4" Text="Age" Grid.Row="2" VerticalAlignment="Center"/>
- <TextBox Margin="4" Text="{Binding Path = Eyeobj.Farbe}" Grid.Column="3" Grid.Row="2"/>
- <TextBlock Margin="3" Text="{Binding Path=Eyeobj.Farbe}" Grid.Row="2" Grid.Column="3" x:Name="testbox"></TextBlock>
- <Button Margin="4" Grid.Row="3" Click="Button_Click"></Button>
- </Grid>
- </Window>
- using System;
- using System.Collections.Generic;
- using System.ComponentModel;
- using System.Linq;
- using System.Runtime.CompilerServices;
- using System.Text;
- using System.Threading.Tasks;
- namespace DataContextDemo
- {
- public class Augen : INotifyPropertyChanged
- {
- public event PropertyChangedEventHandler PropertyChanged;
- public string farbe = "Blau";
- public Augen(string farbe)
- {
- Farbe = farbe;
- }
- //public PropertyChangedEventHandler handler = PropertyChanged;
- private void NotifyPropertyChanged([CallerMemberName] String propertyName = "")
- {
- PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));
- }
- public string Farbe
- {
- get
- {
- return this.farbe;
- }
- set
- {
- this.farbe = value;
- NotifyPropertyChanged();
- }
- }
- }
- }
Add Comment
Please, Sign In to add comment