状況
UWPのComboBox設置及びバインディングのデータも正しくできたはずなのに、下図のように中身が空っぽになってしまう
コンソールにはこんなエラーが表示されている。
Error : BindingExeption path error: 'Content' property not found on 'XXXXXX.TaskDisplayInfo'. BindingExpression: Path='Content' DataItem='Xxxxx.TaskDisplayInfo'; target element is 'Windows.UI.Xaml.Controls.TextBlock' (Name='null'); target property is 'Text' (type 'String')
コンパイルエラーは起きてないし、絶対に取得できるはずなのに・・・
対処方法
ItemSourceに設定したクラスの定義は
public class TaskDisplayInfo { public string EachTaskId = default; public string Content = default; }
ではだめで
public class TaskDisplayInfo { public string EachTaskId { get; set; } = default; public string Content { get; set; } = default; }
というように、getterを付けないと、せっかく値を設定しても取得できないですよ。(自分への戒め)
(getter, setter両方なければ値の設定だけなら問題なくできる。getterをつけるならsetterも付けないと値の設定はできない。)