好吧,我就是不明白。请告诉我为什么我的 ListBox 中没有任何项目(现在应该是两个字符串“empty”和“stuff”):
XAML:
<Window.DataContext>
<Windows:SettingsWindowModel x:Name="model"/>
</Window.DataContext>
<Window.Resources>
<DataTemplate x:Key="ListItemTemplate">
<ListBoxItem Content="{Binding}" />
</DataTemplate>
</Window.Resources>
<ListBox Name="listBoxActivities" SelectionChanged="ListBoxActivitiesSelectionChanged"
ItemsSource="{Binding Path=IgnoredActivities}"
HorizontalAlignment="Left" VerticalAlignment="Top" MinHeight="40" MinWidth="200"
Padding="5,100,5,0" Height="100" Margin="0,207,0,0" ItemTemplate="{StaticResource ListItemTemplate}" />
在设置窗口模型中:
private ObservableCollection<String> _ignoredActivities;
public ObservableCollection<String> IgnoredActivities
{
get
{
if (_ignoredActivities == null)
{
// empty
_ignoredActivities = new ObservableCollection<String>() { "empty","stuff" };
}
return _ignoredActivities;
}
}
还有什么需要知道的吗?我忘记了什么?
编辑:也许我应该补充一点,VisualStudio + ReSharper 也没有显示下划线和编译错误。甚至没有警告。