動作環境
Windows 7 Pro (32bit)
Microsoft Visual Studio 2017 Community
Sublime Text 2
http://gushwell.ldblog.jp/archives/52301656.html
を参考に学習中。
エラー
code
MainWindow.xaml.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
//
using System.ComponentModel;
namespace _170605_t1120_singleBinding
{
/// <summary>
/// MainWindow.xaml の相互作用ロジック
/// </summary>
public partial class MainWindow : Window
{
public MainWindow()
{
InitializeComponent();
}
}
public class Greeing : INotifyPropertyChanged
{
private bool _isFriendly;
public bool IsFriendly
{
get { return _isFriendly; }
set {
if (value != this._isFriendly)
{
this._isFriendly = value;
NotifyPropertyChanged("IsFriendly");
}
}
}
public event PropertyChangedEventHandler hndlr;
private void NotifyPropertyChanged(string info)
{
if (hndlr != null)
{
hndlr(this, new PropertyChangedEventArgs(info));
}
}
public void Greet()
{
NotifyPropertyChanged("Message");
}
}
}
エラーメッセージ
'Greeting'はインターフェイスメンバー 'INotifyPropertyChange.ProPertyChanged'を実装しません。
対処
赤波線のところにマウスカーソルを持っていく。
考えられる修正内容を表示する (Alt+EnterまたはCtrl*.)
という記載をクリックしてみると以下が表示される。
次に「インターフェイスを実装します。」を選択すると以下の行が追加された。
public event PropertyChangedEventHandler PropertyChanged;
PropertyChanged
という名前でなく、自分で勝手に決めたhndlrという命名が間違いだった。
間違い
public event PropertyChangedEventHandler hndlr;
IDEのこの便利な機能はどこまで使っていいものかは要検討。