Mvvm Windows Phone 8全景绑定错误?
我在WindowsPhone8上遇到了全景控件的问题。 创建了一个项目,使用基于WP Panorama项目模板的简单代码测试问题。 因此,我使用INotifyPropertyChanged接口MVVM绑定到一个可观察的集合Mvvm Windows Phone 8全景绑定错误?,mvvm,windows-phone-8,binding,Mvvm,Windows Phone 8,Binding,我在WindowsPhone8上遇到了全景控件的问题。 创建了一个项目,使用基于WP Panorama项目模板的简单代码测试问题。 因此,我使用INotifyPropertyChanged接口MVVM绑定到一个可观察的集合 <phone:PhoneApplicationPage <! ... > <!--LayoutRoot is the root grid where all page content is placed--> <Grid x:Nam
<phone:PhoneApplicationPage
<! ... >
<!--LayoutRoot is the root grid where all page content is placed-->
<Grid x:Name="LayoutRoot" Background="Transparent">
<!--Panorama control-->
<phone:Panorama ItemsSource="{Binding PageTitles}"
Title="Panorama Test">
<phone:Panorama.HeaderTemplate>
<DataTemplate>
<Grid Width="410" Margin="-2,0,0,0">
<TextBlock d:DataContext="{Binding}" Text="{Binding Title}" HorizontalAlignment="Left" Style="{StaticResource PanoramaItemHeaderTextStyle}" />
</Grid>
</DataTemplate>
</phone:Panorama.HeaderTemplate>
<phone:Panorama.Background>
<ImageBrush ImageSource="/Assets\PanoramaBackground.png"/>
</phone:Panorama.Background>
<phone:PanoramaItem Name="Screen1">
<Grid Margin="0,-6,0,12">
<Border BorderThickness="1" Width="420" Height="500" BorderBrush="#FFFFC700" Background="#FFFFC700"/>
</Grid>
</phone:PanoramaItem>
<phone:PanoramaItem Name="Screen2">
<Grid Margin="0,-6,0,12">
<Border BorderThickness="1" Width="420" Height="500" BorderBrush="#FFFFC700" Background="#FFFFC700"/>
</Grid>
</phone:PanoramaItem>
<phone:PanoramaItem Name="Screen3">
<Grid Margin="0,-6,0,12">
<Border BorderThickness="1" Width="420" Height="500" BorderBrush="#FFFFC700" Background="#FFFFC700"/>
</Grid>
</phone:PanoramaItem>
<phone:PanoramaItem Name="Screen4" >
<Grid Margin="0,-6,0,12">
<Border BorderThickness="1" Width="420" Height="500" BorderBrush="#FFFFC700" Background="#FFFFC700"/>
</Grid>
</phone:PanoramaItem>
</phone:Panorama>
</Grid>
在Visual Studio 2013 Design视图中,我看到的不是页面内容,而是一行内容:
_.di28.Injection.Viewmodels.ItemViewModel
在Emulator中运行时,它会显示:
归纳法.Viewmodels.ItemViewModel
我已经用我能想到和找到的所有方法重新构造了绑定,但问题仍然存在。
这是Windows Phone 8下全景控件的一个错误吗?不确定它是否能解决您的问题,但您误解了一些事情: ItemsSource属性不仅用于标题,而且用于整个PanoramaItems集合。 在此之后,不应重新定义每个全景项目,而应使用数据模板:与HeaderTemplate类似:
<Grid x:Name="LayoutRoot" Background="Transparent">
<!--Panorama control-->
<phone:Panorama ItemsSource="{Binding PageTitles}"
Title="Panorama Test">
<phone:Panorama.HeaderTemplate>
<DataTemplate>
<Grid Width="410" Margin="-2,0,0,0">
<TextBlock d:DataContext="{Binding}" Text="{Binding Title}" HorizontalAlignment="Left" Style="{StaticResource PanoramaItemHeaderTextStyle}" />
</Grid>
</DataTemplate>
</phone:Panorama.HeaderTemplate>
<phone:Panorama.Background>
<ImageBrush ImageSource="/Assets\PanoramaBackground.png"/>
</phone:Panorama.Background>
<phone:Panorama.ItemTemplate>
<DataTemplate>
<phone:PanoramaItem>
<Grid Margin="0,-6,0,12">
<Border BorderThickness="1" Width="420" Height="500" BorderBrush="#FFFFC700" Background="#FFFFC700"/>
</Grid>
</phone:PanoramaItem>
</DataTemplate>
</phone:Panorama.ItemTemplate>
</phone:Panorama>
我现在不能测试,但至少你知道了。希望这有帮助 谢谢你的回复。。。我尝试了它,但它只部分起作用,因为代码在模拟器中运行,但会导致Visual Studio 2013设计屏幕因NullReferenceException而崩溃。在任何情况下,如果我希望每个全景项目都有不同的内容,该怎么办?有两个选项:如果您确切地知道要显示什么,那么您不应该使用模板方法,只需定义每个全景项目,包括它们在xaml中的标题。相反,如果你想动态添加全景项目,你应该把你的页面标题变成一个更大的对象,它不仅包含全景项目的标题,还包含其他属性,比如背景、内容等等。。。您为什么要尝试绑定Panorama ItemsSource而不是在xaml中直接定义每个Panorama Item?是的,我想使用单个MVVM数据源填充Panorama Item标题,并将相同的数据用于LongListSelector,作为放置在Panorama最右侧页面的菜单。LongListSelector项将使用数据模板中MVVM数据源的图像文件名、标题和帮助文本。