2011-05-16 129 views

回答

23

沒有辦法自動爲您的應用程序中的所有標題執行此操作。你需要爲每一個設置風格。

隱式樣式即將在芒果更新中,並應該允許這樣做。

更新
以下是您現在可以執行的操作。

爲你想要的FontSzie創建一個全局模板樣式。喜歡的東西:

<Application.Resources> 
    <DataTemplate x:Key="MyItemHeaderTemplate"> 
     <Grid> 
      <ContentPresenter> 
       <TextBlock Text="{Binding}" FontSize="20" /> 
      </ContentPresenter> 
     </Grid> 
    </DataTemplate> 
</Application.Resources> 

然後在我希望有風格的這種方式我設置了HeaderTemplate中每PanoramaItem:

<controls:PanoramaItem Header="first" HeaderTemplate="{StaticResource MyItemHeaderTemplate}"> 
    // ... 
</controls:PanoramaItem> 
+0

「set style」:你的意思是爲HeaderTemplate設置DataTemplate?如果是這樣,我是否需要爲每個4個全景項目創建4個DataTemplates,因爲每個項目標題都不同?或者我可以以某種方式將一個DataTemplate綁定到PanoramaItem.Header屬性? – Buju 2011-05-16 15:11:19

+0

啊thx。我錯過了Text =「{Binding}」的部分......我不知道如何從DataTemplate中訪問標題字符串。有沒有辦法查看它可以在DataTemplate中綁定哪些屬性,如果這樣的事情再次發生在我身上? – Buju 2011-05-16 17:12:19

1

您可以創建自己的PanoramaItem控制和使用generic.xaml應用自定義PanoramaItem樣式。

public class MyPanoramaItem : Microsoft.Phone.Controls.PanoramaItem 

    { 
     public MyPanoramaItem() 
     { 
      DefaultStyleKey = typeof(MyPanoramaItem); 
     } 
    } 

然後創建主題\ Generic.xaml

<ResourceDictionary 
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" 
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" 
    xmlns:local="clr-namespace:YourProjectNamespace"> 

    <Style TargetType="local:MyPanoramaItem"> 
     <!—your custom PanoramaItem style-->  
    </Style> 
</ResourceDictionary> 

然後使用您的自定義全景像這樣:

xmlns:controls="clr-namespace:Microsoft.Phone.Controls;assembly=Microsoft.Phone.Controls" 
xmlns:local="clr-namespace:YourProjectNamespace" 

<Grid x:Name="LayoutRoot" Background="Transparent"> 
     <!--Panorama control--> 
     <controls:Panorama Title="my application"> 
      <controls:Panorama.Background> 
       <ImageBrush ImageSource="PanoramaBackground.png"/> 
      </controls:Panorama.Background> 

      <!--Panorama item one--> 
      <local:MyPanoramaItem Header="first item"> 
      </ local:MyPanoramaItem > 
     </controls:Panorama> 

更多generic.xaml和它的使用,你可以找到here

5

這曾是我的一個棘手的問題也是如此。不過,我已經找到了一個非常簡單的解決方案來處理您想要調整大小的每個頭項目/ fontweight/font ... so-on。我從當前正在處理的項目中插入一段代碼。注意控件的xaml部分:PanoramaItem.HeaderTemplate。這是修改標題項目的模板。祝你好運!

<!--Panorama item one--> 
     <controls:PanoramaItem Header="Locations"> 
      <Grid> 
       <ListBox Height="498" HorizontalAlignment="Left" Margin="2,0,0,0" Name="listBox1" VerticalAlignment="Top" Width="424" /> 
      </Grid> 

      <controls:PanoramaItem.HeaderTemplate> 
       <DataTemplate> 
        <TextBlock Text="{Binding Content, RelativeSource={RelativeSource TemplatedParent}}" FontSize="55" FontFamily="Segoe WP Bold" Foreground="Black" TextAlignment="Left" FontWeight="Normal" FontStyle="Italic" /> 
       </DataTemplate> 
      </controls:PanoramaItem.HeaderTemplate> 


     </controls:PanoramaItem>