Created
December 2, 2015 07:10
-
-
Save veigr/4124232e567293b7628b to your computer and use it in GitHub Desktop.
.NET 4.5 をターゲットにした時のみ、private setter プロパティに TwoWay Binding できる問題
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"> | |
<StackPanel> | |
<TextBox Text="{Binding Hoge, Mode=TwoWay}"/> | |
<TextBox Text="{Binding Hoge, Mode=TwoWay}"/> | |
</StackPanel> | |
</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.ComponentModel; | |
using System.Diagnostics; | |
using System.Windows; | |
namespace WpfApplication1 | |
{ | |
/// <summary> | |
/// MainWindow.xaml の相互作用ロジック | |
/// </summary> | |
public partial class MainWindow : Window, INotifyPropertyChanged | |
{ | |
private string _Hoge; | |
public string Hoge | |
{ | |
get { return _Hoge; } | |
private set | |
{ | |
_Hoge = value; | |
Debug.WriteLine("Hoge Changed"); | |
this.PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(nameof(this.Hoge))); | |
} | |
} | |
public MainWindow() | |
{ | |
InitializeComponent(); | |
this.DataContext = this; | |
this.Hoge = "Hoge!"; | |
} | |
public event PropertyChangedEventHandler PropertyChanged; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment