Skip to content

Instantly share code, notes, and snippets.

@veigr
Created December 2, 2015 07:10
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 veigr/4124232e567293b7628b to your computer and use it in GitHub Desktop.
Save veigr/4124232e567293b7628b to your computer and use it in GitHub Desktop.
.NET 4.5 をターゲットにした時のみ、private setter プロパティに TwoWay Binding できる問題
<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>
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