2015-11-02 27 views
0

我正在將Wp81應用程序移植到UWP,並且似乎Hub佈局策略已更改,並且它不再調整HubSections寬度以將其拉伸(幾乎)到屏幕寬度。如何在UWP中實現這個功能而不在HubSections上設置絕對寬度?UWP中的HubSection默認寬度

詳細瞭解我的使用情況: 在我HubSection我有一個形象,那不是被收縮到屏幕寬度(幾乎是 - 使下部分是分享範圍),它延伸到它的原生寬度。 TextBlock也是如此。看來在UWP HubSection沒有根據屏幕寬度設置寬度或MaxWith。

+0

您是否嘗試過檢查/修改控件的樣式? – Romasz

+0

@Romasz是的,Hub風格或HubSection風格沒有明確的寬度設置。 – bitninja

回答

0

樞紐的目的是讓用戶發現的東西。所以該部分默認情況下不會被拉伸到全屏。對於你的情況,你最好試試Pivot控制。 Here是Pivot和Hub的設計指南。

此外,如果你仍然想使用集線器和想要的風格,以適應不同的屏幕尺寸,下面是一個簡單的解決方案由VisualStateManager:

<Grid Background="{ThemeResource ApplicationPageBackgroundThemeBrush}"> 
    <VisualStateManager.VisualStateGroups> 
     <VisualStateGroup> 
      <VisualState x:Name="Phone" > 
       <VisualState.StateTriggers> 
        <AdaptiveTrigger MinWindowWidth="1" /> 
       </VisualState.StateTriggers> 
       <VisualState.Setters> 
        <Setter Target="HeroImg.Width" Value="100" /> 
       </VisualState.Setters> 
      </VisualState> 
      <VisualState x:Name="Tablet" > 
       <VisualState.StateTriggers> 
        <AdaptiveTrigger MinWindowWidth="600" /> 
       </VisualState.StateTriggers> 
       <VisualState.Setters> 
        <Setter Target="HeroImg.Width" Value="800" /> 
       </VisualState.Setters> 
      </VisualState> 
     </VisualStateGroup> 
    </VisualStateManager.VisualStateGroups> 

    <Hub Header="News" > 
     <HubSection Header="Hero" x:Name ="HeroImg" > 
      <HubSection.Background> 
       <ImageBrush ImageSource="Assets/circle_hero.jpg" Stretch="UniformToFill"/> 
      </HubSection.Background> 
     </HubSection> 

    </Hub> 
</Grid> 
+0

我的用例符合Hub設計準則。至少讓我們假設它是這樣做的。我在關於我想實現的問題中添加了詳細的信息。 – bitninja

+0

HubSection具有「寬度」,「最小寬度」,「最大寬度」屬性。你可以在這裏查看:https://msdn.microsoft.com/query/dev14.query?appId=Dev14IDEF1&l=zh-CN&k=k(Windows.UI.Xaml.Controls.HubSection);k(VS.XamlEditor);k (TargetFrameworkMoniker-.NETCore,Version%3Dv4.5.1)&rd = true –

+0

如果要適應屏幕大小,可以使用VisualStateGroups。您可以參考此示例中的scenario2:https://code.msdn.microsoft.com/XAML-Hub-control-sample-5d116fa9 –