コンボボックスのコンテンツをWPFのリストで埋めたい。私は通常winformでそれを行うことができますが、wpfは少し異なって見えます。
XAMLでコードを作成しません。コントロール全体が動的に実行時に作成されます。
これが私のコードです
cmbKriterKategoriはコンボボックスです。
cmbKriterKategori.DisplayMemberPath = "Value";
cmbKriterKategori.SelectedValuePath = "Key";
cmbKriterKategori.ItemsSource = yHelper.GetCriterList().ToList();
エラーが発生します
ItemsSourceを使用する前に、Itemsコレクションを空にする必要があります。
そして私もそのように試みました
cmbKriterKategori.DisplayMemberPath = "Value";
cmbKriterKategori.SelectedValuePath = "Key";
cmbKriterKategori.DataContext = yHelper.GetCriterList().ToList();
エラーは発生しませんが、コンボボックスにはアイテムがありません。
yHelper.GetCriterList()。ToList(); この関数はList>を返し、yHelper.GetCriterList()はDictionaryを返します。
私はそのコードをwinformで使用しましたが、機能します。
cmbKriterKategori.DisplayMember = "Value";
cmbKriterKategori.ValueMember ="Key";
cmbKriterKategori.DataSource = yhelper.GetCriterList().ToList();
それで、問題は何ですか?