Skip to content

Instantly share code, notes, and snippets.

@milleniumbug
Created July 25, 2016 20:21
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save milleniumbug/5adbf260a5fc1d9def565b340720ddce to your computer and use it in GitHub Desktop.
Save milleniumbug/5adbf260a5fc1d9def565b340720ddce to your computer and use it in GitHub Desktop.
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));
}
}
}
<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 HorizontalContentAlignment="Stretch" ItemsSource="{Binding People}">
<ListBox.ItemTemplate>
<DataTemplate>
<Border BorderBrush="Green" BorderThickness="1" Margin="0,3,0,3">
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="Auto" />
<RowDefinition Height="Auto" />
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="Auto" />
<ColumnDefinition Width="*" />
</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>
</Border>
</DataTemplate>
</ListBox.ItemTemplate>
</ListBox>
</Grid>
</Window>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment