内部にチェックボックスがある単純なコンボボックスがあります。
<ComboBox Height="23" HorizontalAlignment="Left" Margin="158,180,0,0" Name="comboBox1" VerticalAlignment="Top" Width="120" ItemsSource="{Binding collection}">
<ComboBox.ItemTemplate>
<DataTemplate>
<StackPanel Orientation="Horizontal">
<CheckBox Content="{Binding Name}"></CheckBox>
</StackPanel>
</DataTemplate>
</ComboBox.ItemTemplate>
</ComboBox>
データ コンテキストは単なるコード ビハインドであり、それをテストするために次のコードを使用します。
public ObservableCollection<Foo> collection { get; set; }
private void button1_Click(object sender, RoutedEventArgs e)
{
collection = new ObservableCollection<Foo>();
this.comboBox1.ItemsSource = collection;
Foo f = new Foo("DSD");
collection.Add(f);
}
コードにあるように ItemsSource を設定すると正常に動作しますが、Xaml で ItemsSource を設定したいのですが、上記の Xaml を使用しても動作しません。また、Path = "" に設定しようとしました。理由を知っている人はいますか?
ありがとう