DataBindingについての私の理解はまだ「それに取り組んでいる」レベルなので、ここに私の問題があります。私はこのデータを持っています:
private class User
{
public string username { get; set; }
public string real_name { get; set; }
}
ObservableCollection<User> users = new ObservableCollection<User>();
...adds stuff...
CollectionView view = (CollectionView)CollectionViewSource.GetDefaultView(users);
これを2列のリストボックスに表示したいと思います。次のようにして、2列のComboBoxにアクセスしました。
<ComboBox Height="23" HorizontalAlignment="Left" Margin="114,23,0,0" Name="comboBox_client" VerticalAlignment="Top" Width="113" IsEditable="True" ItemsSource="{Binding}" >
<ComboBox.ItemTemplate>
<DataTemplate>
<StackPanel Orientation="Horizontal">
<TextBlock Text="{Binding username}" Name="left" Width="50" />
<TextBlock Text="{Binding real_name}" Name="right" Width="100" />
</StackPanel>
</DataTemplate>
</ComboBox.ItemTemplate>
</ComboBox>
と
comboBox_client.ItemsSource = view;
しかし、ItemTemplateが表示されないため、ListBoxにステップオーバーする方法がわかりません。また、上記のXamlが実際に行っていることの背後にある概念がわかりません。ItemTemplateの部分を取り出して、残りをListBoxで試してみると、System.Windows.DataTemplateでいっぱいのリストボックスだけになります。
正しい方向に向けてください。