2014-03-13 95 views
0

我遇到過Windows Phone 8上的全景控制問題。 創建了一個項目,使用基於WP Panorama Project模板的簡單代碼來測試問題。 因此,我使用INotifyPropertyChanged接口(MVVM)綁定到Observable集合。Windows Phone 8全景綁定錯誤?

<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設計視圖中發生的網頁內容,我看到我一行,上面寫着:

_.di28.Induction.Viewmodels.ItemViewModel

,並在模擬器中運行時,它讀取:

Induction.Viewmodels.ItemViewModel

我重新調整了我能想到和發現的所有方式的綁定,但問題仍然存在。 這是Windows Phone 8下的全景控制的錯誤嗎?

回答

0

不確定它是否會解決您的問題,但您誤解了某些內容: ItemsSource屬性不僅用於標題,還用於整個PanoramaItems集合。 你不應該重新定義每個PanoramaItem之後,但使用一個DataTemplate來代替:就像在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> 

我現在不能測試,但至少你的想法。希望這可以幫助 !

+0

感謝您的回覆......我試過了,它只是部分工作,因爲代碼在模擬器中運行,但會導致Visual Studio 2013設計屏幕崩潰並導致NullReferenceException。 無論如何,如果我希望每個PanoramaItem具有不同的內容呢? – PythonesqueSpam

+0

有兩種選擇:如果您確切知道要顯示的內容,那麼您不應該使用模板方法,只需定義每個PanoramaItem,包括它們在xaml中的標題。相反,如果你想能夠添加PanoramaItems動態,你應該把你的PageTitle變成一個更大的對象,它不僅包含PanoramaItem標題,還包含其他屬性,比如它的背景,內容等等。您試圖綁定Panorama ItemsSource而不是直接定義xaml中的每個PanoramaItem的原因? – MakanWG

+0

是的,我想使用單個MVVM數據源來填充PanoramaItem標題(標題),並將LongListSelector的相同數據用作放置爲Panorama最右側頁面的菜單。 LongListSelector Items將使用來自DataTemplate中MVVM數據源的圖像文件名