-
-
Save milleniumbug/67377c5667fcdb187bb9accbf52aa5ef to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System.Collections.ObjectModel; | |
using System.ComponentModel; | |
using System.Runtime.CompilerServices; | |
namespace Katas | |
{ | |
public class Foo | |
{ | |
public ObservableCollection<Person> People { get; } = new ObservableCollection<Person> | |
{ | |
new Person {FirstName = "Johan", LastName = "Larsson"}, | |
new Person {FirstName = "Bug", LastName = "1000"} | |
}; | |
} | |
public class Person : INotifyPropertyChanged | |
{ | |
private string firstName; | |
private string lastName; | |
public event PropertyChangedEventHandler PropertyChanged; | |
public string FirstName | |
{ | |
get { return this.firstName; } | |
set | |
{ | |
if (value == this.firstName) return; | |
this.firstName = value; | |
this.OnPropertyChanged(); | |
} | |
} | |
public string LastName | |
{ | |
get { return this.lastName; } | |
set | |
{ | |
if (value == this.lastName) return; | |
this.lastName = value; | |
this.OnPropertyChanged(); | |
} | |
} | |
protected virtual void OnPropertyChanged([CallerMemberName] string propertyName = null) | |
{ | |
this.PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName)); | |
} | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<Window x:Class="Katas.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:local="clr-namespace:Katas" | |
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" | |
Title="MainWindow" | |
Width="525" | |
Height="350" | |
mc:Ignorable="d"> | |
<Window.DataContext> | |
<local:Foo /> | |
</Window.DataContext> | |
<Grid> | |
<ListBox ItemsSource="{Binding People}"> | |
<ListBox.ItemTemplate> | |
<DataTemplate> | |
<Grid> | |
<Grid.RowDefinitions> | |
<RowDefinition Height="Auto" /> | |
<RowDefinition Height="Auto" /> | |
<RowDefinition Height="*" /> | |
</Grid.RowDefinitions> | |
<Grid.ColumnDefinitions> | |
<ColumnDefinition Width="Auto" /> | |
<ColumnDefinition Width="Auto" /> | |
</Grid.ColumnDefinitions> | |
<TextBlock Grid.Row="0" | |
Grid.Column="0" | |
Text="First Name" /> | |
<TextBox Grid.Row="0" | |
Grid.Column="1" | |
HorizontalContentAlignment="Stretch" | |
Text="{Binding FirstName}" /> | |
<TextBlock Grid.Row="1" | |
Grid.Column="0" | |
Text="Second Name" /> | |
<TextBox Grid.Row="1" | |
Grid.Column="1" | |
HorizontalContentAlignment="Stretch" | |
Text="{Binding LastName}" /> | |
</Grid> | |
</DataTemplate> | |
</ListBox.ItemTemplate> | |
</ListBox> | |
</Grid> | |
</Window> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment