[WPF]値やReactiveCommandをBindするときは必ずプロパティにしましょう
WPFのお話です。こんな感じで、ReactiveCommandや値をバインドしたい場合。
[WPF][ImageAwesome] IconをBindしたい
フィールドにするとエラーも何も出ず、意図した動作ができない。ハマる。必ずプロパティにしましょう。
参考:
[WPF][ImageAwesome] IconをBindしたい
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
public class TestModel | |
{ | |
public ReactiveCommand cw { get; } = new ReactiveCommand(); | |
//↓エラーも出ず、意図した動作ができない。ハマる。 | |
//public ReactiveCommand cw = new ReactiveCommand(); | |
public Test() | |
{ | |
//todo: ボタンを押すとhogeが出力されるようにする | |
cw.Subscribe(_ => { System.Diagnostics.Debug.WriteLine("hoge"); }); | |
} | |
} |
フィールドにするとエラーも何も出ず、意図した動作ができない。ハマる。必ずプロパティにしましょう。
参考:
WPFのデータバインディングは、依存関係プロパティとプロパティの間の同期をとる機能になります。
WPF4.5入門 その55 「Binding その1」
コメント
コメントを投稿