我在 mainviewmodel 中有 2 个可观察的集合,现在我需要将这两个集合绑定到 xaml 文件中。
<!--Panorama control-->
<controls:Panorama x:Name="AppPano" ItemsSource="{Binding SlidesCollections}" SelectionChanged="AppPano_SelectionChanged" >
<controls:Panorama.Background>
<ImageBrush ImageSource="PanoramaBackground.png"/>
</controls:Panorama.Background>
<controls:Panorama.ItemTemplate>
<DataTemplate>
<Grid VerticalAlignment="Top" HorizontalAlignment="Left" Margin="0,-100,0,0">
<StackPanel HorizontalAlignment="Center" Height="250" Width="200" VerticalAlignment="Top">
<TextBlock Text="{Binding Title}" HorizontalAlignment="Center" FontSize="200" Width="Auto"/>
</StackPanel>
<ListBox x:Name="ItemsList" ItemsSource="{Binding SlideItemList}" Margin="0,250,0,0" VerticalAlignment="Top" SelectionChanged="ItemsList_SelectionChanged" Height="430">
<ListBox.ItemTemplate>
<DataTemplate>
<StackPanel x:Name="ImgStack" HorizontalAlignment="Left" Height="430" VerticalAlignment="Top" Width="370" Margin="50,0,0,0">
<Image Height="350" Width="360" Source="{Binding Image}"/>
</StackPanel>
</DataTemplate>
</ListBox.ItemTemplate>
</ListBox>
</Grid>
</DataTemplate>
</controls:Panorama.ItemTemplate>
</controls:Panorama>
主视图模型.cs
public KidsAppMainViewModel()
{
this.SlidesCollections = new ObservableCollection<AppItemsListViewModel>();
this.SlideItemList = new ObservableCollection<AppItemViewModel>();
}
public ObservableCollection<AppItemsListViewModel> SlidesCollections {get; set;}
public ObservableCollection<AppItemViewModel> SlideItemList {get; set;}
MainXaml.cs
DataContext = App.ViewModel
应用程序.xaml.cs
public static MainViewModel viewModel = new MainViewModel();
public MainViewModel ViewModel
{ get { return viewModel;}}
问题:
当我运行应用程序时,全景项目模板绑定工作正常,但列表项目模板对我不起作用。我尝试过使用collectionview源的其他方式,它对我有用,但绑定项目太慢了。
请建议我如何直接绑定这个集合..