2016-07-21 26 views
0

AdaptiveTrigger與MinWindowWidth = 2160似乎並不工作。我需要它來處理Microsoft Surface Pro 3屏幕分辨率(2160x1440)。的VisualState AdaptiveTrigger MinWindowWidth = 2160不起作用

看看下面這個簡單的代碼:

<Page 
    x:Class="TestUWP.MainPage" 
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" 
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" 
    xmlns:local="using:TestUWP" 
    xmlns:d="http://schemas.microsoft.com/expression/blend/2008" 
    xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 
    mc:Ignorable="d" d:DesignWidth="2160" d:DesignHeight="1440"> 

    <Grid> 
     <VisualStateManager.VisualStateGroups> 
      <VisualStateGroup> 
       <VisualState> 
        <VisualState.StateTriggers> 
         <AdaptiveTrigger MinWindowWidth="2160" /> 
        </VisualState.StateTriggers> 
        <VisualState.Setters> 
         <Setter Target="brdMain.Background" Value="#bbbbbb"></Setter> 
        </VisualState.Setters> 
       </VisualState> 
       <VisualState> 
        <VisualState.StateTriggers> 
         <AdaptiveTrigger MinWindowWidth="0" /> 
        </VisualState.StateTriggers> 
        <VisualState.Setters> 
         <Setter Target="brdMain.Background" Value="#303030"></Setter> 
        </VisualState.Setters> 
       </VisualState> 
      </VisualStateGroup> 
     </VisualStateManager.VisualStateGroups> 
     <Border x:Name="brdMain"> 
      <TextBlock Text="Testing"></TextBlock> 
     </Border> 
    </Grid> 
</Page> 

你會看到,背景色爲黑色總是(#303030)。 VisualState可以處理的最大寬度是多少?任何想法?

感謝

回答

4

你必須要記住,在UWP測量的有效像素(EPX)完成。見MSDN。 Surface Pro 3與其他Surface平板電腦一樣,具有HiDPI顯示屏和大於1的默認比例因子,這意味着其有效像素分辨率爲,比2160x1440小,即使這是其原始分辨率。

的SP3的默認比例因子爲150%,從而導致的一個1440x960 EPX分辨率。因此,即使最大化窗口,窗口寬度也只有最多1440個epx,這意味着MinWindowWidth="2160"狀態觸發器不會在默認設置下在SP3上觸發。

如果您希望您的狀態觸發器僅在具有HiDPI顯示和/或特定原始分辨率的平板電腦上觸發,則可能需要實施自定義狀態觸發器來檢測所有這些情況。你如何做到這一點超出了這個問題的範圍。

+0

哇,你是絕對正確的!你是如何發現比例係數的? – Sam

+0

@Sam:我希望我能說我擁有一臺Surface Pro 3,但是我只是在店裏看了一臺。無論如何,現在許多手機和平板電腦顯示器都是HiDPI,顯示器縮放比例正在成爲一種常態。這就是爲什麼UWP非常重視有效像素。 – BoltClock

0

我認爲您的尺寸可能會關閉。你有沒有嘗試過其他人?

按照Official MSDN Screen Sizes and Layouts Documentation這些都是您要使用

enter image description here

的原因大小,你可能不希望確切的屏幕尺寸是因爲什麼是從調整下來一點或停止某人上一點?

個人而言,對於更復雜的佈局,我更願意爲每個尺寸創建單獨的視圖。它讓我更好地控制佈局。以下是我如何使用它。

在靜態應用級Ⅰ類有。

public enum DeviceType 
    { 
     Desktop = 0, 
     Phablet = 1, 
     Mobile = 2 
    }  

    public static DeviceType CurrentDevice 
    { 
     get 
     { 
      ApplicationView view = ApplicationView.GetForCurrentView(); 
      Rect rect = view.VisibleBounds; 

      if (rect.Width >= 1024) 
      { 
       return DeviceType.Desktop; 
      } 
      else if (rect.Width >= 720) 
      { 
       return DeviceType.Phablet; 
      } 
      else 
      { 
       return DeviceType.Mobile; 
      } 
     } 
    } 

然後在我的控制中,我只是在我的靜態構造函數中訪問我的靜態類。如果我是移動設備,則加載手機的DefaultStyleKey。如果我是桌面,那麼我加載一個DesktopDefaultStyleKey。

DeviceType device = ApplicationServices.CurrentDevice; 

    switch (device) 
    { 
     case (DeviceType.Desktop): 
      YoutubeVideosPresenter.Content = new YouTubeVideosLayoutDesktop(); 
      break; 
     case (DeviceType.Mobile): 
      YoutubeVideosPresenter.Content = new YouTubeVideosLayoutMobile(); 
      break; 
    }   

當然,這是不是很「自適應」,如果有人操縱的窗口寬度。通過檢查窗口寬度是否已更改,然後可以輕鬆切換樣式,您可以很容易地通過此操作。

+0

嗨安東尼,當你做view.VisibleBounds。該值是物理分辨率還是有效像素? – Sam

+0

https://msdn.microsoft.com/en-us/library/windows/apps/windows.ui.viewmanagement.applicationview。visiblebounds.aspx –

相關問題