2015-12-21 51 views
1

我正在創建Windows通用應用程序VisualStateManager中的UWP多VisualState觸發器

我想要執行與3列結合的佈局。每列顯示不同的信息。

第一個列包含ListView。如果您選擇一個項目,則應顯示第二個列。

第二個列也包含ListView。如果您選擇一個項目,則應該顯示該項目。

第三列顯示一些信息。

我只需要顯示列,顯示一些信息(空白列隱藏)。另外我想添加響應式功能。所以在手機上應該只顯示一個最重要的列。

下面是一個例子

桌面(開始):

| 1 |

桌面(點擊第一個ListView):

| 1 | 2 |

桌面(點擊第二個ListView):

| 1 | 2 | 3 |

移動(啓動):

| 1 |

桌面(點擊第一個ListView):

| 2 |

桌面(點擊第二個ListView控件):

| 3 |

所以我想用兩個StateTriggers創建VisualState

事情是這樣的:

<VisualState x:Name="VSShowThird"> 
    <VisualState.StateTriggers> 
     <AdaptiveTrigger MinWindowWidth="750" /> 
     <StateTrigger IsActive="{Binding Path=ShowThirdColumn}" /> 
    </VisualState.StateTriggers> 
    <VisualState.Setters> 
     <Setter Target="FirstColumn.Visibility" Value="Visible" /> 
     <Setter Target="SecondColumn.Visibility" Value="Visible" /> 
     <Setter Target="ThirdColumn.Visibility" Value="Visible" /> 
    </VisualState.Setters> 
</VisualState> 
<VisualState x:Name="VSShowSecond"> 
    <VisualState.StateTriggers> 
     <AdaptiveTrigger MinWindowWidth="750" /> 
     <StateTrigger IsActive="{Binding Path=ShowSecondColumn}" /> 
    </VisualState.StateTriggers> 
    <VisualState.Setters> 
     <Setter Target="FirstColumn.Visibility" Value="Visible" /> 
     <Setter Target="SecondColumn.Visibility" Value="Visible" /> 
     <Setter Target="ThirdColumn.Visibility" Value="Collapsed" /> 
    </VisualState.Setters> 
</VisualState> 
<VisualState x:Name="VSShowFirst"> 
    <VisualState.StateTriggers> 
     <AdaptiveTrigger MinWindowWidth="750" /> 
    </VisualState.StateTriggers> 
    <VisualState.Setters> 
     <Setter Target="FirstColumn.Visibility" Value="Visible" /> 
     <Setter Target="SecondColumn.Visibility" Value="Collapsed" /> 
     <Setter Target="ThirdColumn.Visibility" Value="Collapsed" /> 
    </VisualState.Setters> 
</VisualState> 

但它不能正常工作。

你能爲此提出任何解決方案嗎?

非常感謝。

+0

我實現這個即時通訊我的應用程序,擴展適應性trager並添加一個屬性是積極的,但我有一些問題,結合室內用 –

回答

1

我創建這個觸發器和我

public class AdaptiveTriggerWithState : AdaptiveTrigger 
{ 
    private double _minWindowHeightProperty; 
    private double _minWindowWidthProperty; 
    private const int INACTIVE_STATE_SIZE = 10000; 

    public static DependencyProperty IsActiveProperty = 
     DependencyProperty.Register(
           "IsActive", 
           typeof(bool), 
           typeof(AdaptiveTriggerWithState), 
           new PropertyMetadata(default(bool), OnIsActive_Changed)); 

    private static void OnIsActive_Changed(DependencyObject d, DependencyPropertyChangedEventArgs e) 
    { 
     var instance = (AdaptiveTriggerWithState)d; 
     instance.IsActive = (bool)e.NewValue; 
    } 

    public bool IsActive 
    { 
     get { return (bool)GetValue(IsActiveProperty); } 
     set 
     { 
      SetValue(IsActiveProperty, value); 
      SetValue(MinWindowHeightProperty, (IsActive ? this._minWindowHeightProperty : INACTIVE_STATE_SIZE)); 
      SetValue(MinWindowWidthProperty, (IsActive ? this._minWindowWidthProperty : INACTIVE_STATE_SIZE)); 
     } 
    } 

    public new System.Double MinWindowHeight 
    { 
     get { return (Double)GetValue(MinWindowHeightProperty); } 
     set 
     { 
      this._minWindowHeightProperty = value; 
      SetValue(MinWindowHeightProperty, (IsActive ? this._minWindowHeightProperty : INACTIVE_STATE_SIZE)); 
     } 
    } 
    public new System.Double MinWindowWidth 
    { 
     get { return (Double)GetValue(MinWindowWidthProperty); } 
     set 
     { 
      this._minWindowWidthProperty = value; 
      SetValue(MinWindowWidthProperty, (IsActive ? this._minWindowWidthProperty : INACTIVE_STATE_SIZE)); 
     } 
    } 


}