ItemsControlにバインドしようとしているObservableコレクションがあります。以下は私のコードのスニペットです。
クラスSample.ViewModel:
//Observabale collection getter/setter property
public ObservableCollection<SQuestion> SList
{
get
{
return _sList;
}
set
{
if (_sList == value)
return;
_sList = value;
if(PropertyChanged!=null)
PropertyChanged(this, new PropertyChangedEventArgs("ListOfSamples"));
}
}
.xamlコード:
View / Mainwindow.xaml
<ItemsControl Height="422" HorizontalAlignment="Left" Margin="12,12,0,0" Name="listBox1" VerticalAlignment="Top" Width="751" ItemsSource="{Binding SList}" ItemTemplate="{StaticResource perItemTemplate}"/>
上記のコードでは、ItemsSourceバインディングを指定していますが、アプリケーションを実行すると、リストがItemsControlに表示されず、すべてが空白で表示されます。
ただし、.csコードビハインドからリストボックスにソースを割り当てようとするとのようlistBox1.ItemsSource = SList
に、リストボックスにデータが入力され、期待どおりに機能します。
コードビハインドを使用せずにxamlから直接バインドできるようにするために、私が行っているBindingの上記の問題を誰かが指摘できますか?