Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
.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