Last active
September 15, 2016 12:38
-
-
Save kuttsun/b4db11f45770c68e2cfe0c766aacee50 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
/// <summary> | |
/// MainWindow.xaml の相互作用ロジック | |
/// </summary> | |
public partial class MainWindow : Window | |
{ | |
public MainWindow() | |
{ | |
InitializeComponent(); | |
// バインディング対象のインスタンスを、MainWindowViewModelに設定 | |
this.DataContext = new MainWindowViewModel(); | |
} | |
} |
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="WpfApplication1.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:WpfApplication1" | |
mc:Ignorable="d" | |
Title="MainWindow" Height="350" Width="525"> | |
<Grid> | |
<TextBox x:Name="textBox" HorizontalAlignment="Left" Height="23" Margin="10,10,0,0" TextWrapping="Wrap" Text="{Binding SampleText, UpdateSourceTrigger=PropertyChanged}" VerticalAlignment="Top" Width="120"/> | |
<Label x:Name="label" Content="{Binding SampleLabel}" HorizontalAlignment="Left" Margin="10,38,0,0" VerticalAlignment="Top"/> | |
</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
/// <summary> | |
/// MainWindowに対するViewModel | |
/// </summary> | |
class MainWindowViewModel | |
{ | |
// バインディングされる値を保持するフィールド | |
private string sampleText_; | |
// バインディング対象のプロパティ | |
public string SampleText | |
{ | |
get | |
{ | |
return sampleText_; | |
} | |
set | |
{ | |
sampleText_ = value; | |
SampleLabel = value;// ラベルの値も連動させる | |
} | |
} | |
// バインディングされる値を保持するフィールド | |
private string sampleLabel_ = ""; | |
// バインディング対象のプロパティ | |
public string SampleLabel | |
{ | |
get | |
{ | |
return sampleLabel_; | |
} | |
set | |
{ | |
sampleLabel_ = value; | |
} | |
} | |
/// <summary> | |
/// コンストラクタ | |
/// </summary> | |
public MainWindowViewModel() | |
{ | |
SampleText = "Sample"; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment