Last active
December 25, 2015 09:09
-
-
Save posaunehm/6951770 to your computer and use it in GitHub Desktop.
C# の素晴らしさを語る会 デモ用コード。 Install-Package PropertyChanged.Fody
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="FodyPractice.MainWindow" | |
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" | |
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" | |
Title="MainWindow" Height="350" Width="525"> | |
<Grid> | |
<TextBox HorizontalAlignment="Left" Height="23" Margin="29,25,0,0" TextWrapping="Wrap" Text="{Binding FirstName}" VerticalAlignment="Top" Width="120"/> | |
<TextBox HorizontalAlignment="Left" Height="23" Margin="199,25,0,0" TextWrapping="Wrap" Text="{Binding FamilyName}" VerticalAlignment="Top" Width="120"/> | |
<TextBlock FontSize="40" HorizontalAlignment="Left" Margin="29,80,0,0" TextWrapping="Wrap" Text="{Binding DisplayName}" VerticalAlignment="Top" Height="60" Width="290"/> | |
</Grid> | |
</Window> |
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.Windows; | |
namespace FodyPractice | |
{ | |
/// <summary> | |
/// MainWindow.xaml の相互作用ロジック | |
/// </summary> | |
public partial class MainWindow : Window | |
{ | |
public MainWindow() | |
{ | |
InitializeComponent(); | |
this.DataContext = new PersonViewModel | |
{ | |
FirstName = "Moriri", | |
FamilyName = "Rin" | |
}; | |
} | |
} | |
} |
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 PropertyChanged; | |
namespace FodyPractice | |
{ | |
[ImplementPropertyChanged] | |
public class PersonViewModel | |
{ | |
public string FirstName { get; set; } | |
public string FamilyName { get; set; } | |
public string DisplayName | |
{ | |
get { return string.Format("{0} {1}", FirstName, FamilyName); } | |
} | |
} | |
} |
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; | |
using System.ComponentModel; | |
namespace FodyPractice | |
{ | |
public class PersonViewModel : INotifyPropertyChanged | |
{ | |
public event PropertyChangedEventHandler PropertyChanged; | |
public string FirstName | |
{ | |
[CompilerGenerated] | |
get | |
{ | |
return this.<FirstName>k__BackingField; | |
} | |
[CompilerGenerated] | |
set | |
{ | |
if (string.Equals(this.<FirstName>k__BackingField, value, StringComparison.Ordinal)) | |
{ | |
return; | |
} | |
this.<FirstName>k__BackingField = value; | |
this.OnPropertyChanged("DisplayName"); | |
this.OnPropertyChanged("FirstName"); | |
} | |
} | |
public string FamilyName | |
{ | |
[CompilerGenerated] | |
get | |
{ | |
return this.<FamilyName>k__BackingField; | |
} | |
[CompilerGenerated] | |
set | |
{ | |
if (string.Equals(this.<FamilyName>k__BackingField, value, StringComparison.Ordinal)) | |
{ | |
return; | |
} | |
this.<FamilyName>k__BackingField = value; | |
this.OnPropertyChanged("DisplayName"); | |
this.OnPropertyChanged("FamilyName"); | |
} | |
} | |
public string DisplayName | |
{ | |
get | |
{ | |
return string.Format("{0} {1}", this.FirstName, this.FamilyName); | |
} | |
} | |
public virtual void OnPropertyChanged(string propertyName) | |
{ | |
PropertyChangedEventHandler propertyChanged = this.PropertyChanged; | |
if (propertyChanged != null) | |
{ | |
propertyChanged(this, new PropertyChangedEventArgs(propertyName)); | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment