2016-03-28 36 views

回答

1

使用AdaptiveTriggers來更改行數和列數作爲控制

<VisualStateManager.VisualStateGroups> 
     <VisualStateGroup> 
      <VisualState> 
       <!-- VisualState to be triggered when window width is >=1000 effective pixels --> 
       <VisualState.StateTriggers> 
        <AdaptiveTrigger MinWindowWidth="1000" /> 
       </VisualState.StateTriggers> 
       <VisualState.Setters> 
        <Setter Target="TextBox1.Visibility" Value="Collapsed" /> 
<Setter Target="TextBox2.Visibility" Value="Collapsed" /> 
<Setter Target="TextBox3.Visibility" Value="Collapsed" /> 
        <Setter Target="myButton1.(Grid.Column)" Value="0" /> 
<Setter Target="myButton2.(Grid.Column)" Value="1" /> 
<Setter Target="myButton3.(Grid.Column)" Value="2" /> 
       </VisualState.Setters> 
      </VisualState> 
      <VisualState> 
       <!-- VisualState to be triggered when window width is >=600 and <1000 effective pixels --> 
       <VisualState.StateTriggers> 
        <AdaptiveTrigger MinWindowWidth="600" /> 
       </VisualState.StateTriggers> 
       <VisualState.Setters> 
        <Setter Target="myButton1.(Grid.Row)" Value="0" /> 
<Setter Target="myButton2.(Grid.Row)" Value="1" /> 
<Setter Target="myButton3.Visibility" Value="Collapsed" /> 
<Setter Target="TextBox1.(Grid.Row)" Value="2" /> 
<Setter Target="TextBox2.Visibility" Value="Collapsed" /> 
<Setter Target="TextBox3.Visibility" Value="Collapsed" /> 
       </VisualState.Setters> 
      </VisualState> 
<VisualState> 
       <!-- VisualState to be triggered when window width is >=0and <1000 effective pixels --> 
       <VisualState.StateTriggers> 
        <AdaptiveTrigger MinWindowWidth="0" /> 
       </VisualState.StateTriggers> 
       <VisualState.Setters> 
        <Setter Target="myButton1.(Grid.Row)" Value="0" /> 

<Setter Target="TextBox1.(Grid.Row)" Value="0" /> 
<Setter Target="TextBox2.(Grid.Row)" Value="1" /> 
<Setter Target="TextBox3.(Grid.Row)" Value="2" /> 
<Setter Target="myButton2.Visibility" Value="Collapsed" /> 
<Setter Target="myButton3.Visibility" Value="Collapsed" /> 
<Setter Target="myButton1.Visibility" Value="Collapsed" /> 
       </VisualState.Setters> 
      </VisualState> 
     </VisualStateGroup> 
    </VisualStateManager.VisualStateGroups> 
    <Grid> 
     <Grid.ColumnDefinitions> 
      <ColumnDefinition Width="Auto" /> 
      <ColumnDefinition Width="Auto" /> 
    <ColumnDefinition Width="Auto" /> 
     </Grid.ColumnDefinitions> 

     <Grid.RowDefinitions> 
      <RowDefinition Height="Auto" /> 
      <RowDefinition Height="Auto" /> 
<RowDefinition Height="Auto" /> 
<RowDefinition Height="Auto" /> 
     </Grid.RowDefinitions> 


     <Button x:Name="myButton1" Content="MyButton" Width="200" /> 
<Button x:Name="myButton2" Content="MyButton" Width="200" /> 
<Button x:Name="myButton3" Content="MyButton" Width="200" /> 
    <TextBox Text="TextBox content" Width="200" Height="20" x:Name="TextBox1"/> 
    <TextBox Text="TextBox content" Width="200" Height="20" x:Name="TextBox2"/> 
    <TextBox Text="TextBox content" Width="200" Height="20" x:Name="TextBox3"/> 

    </Grid> 
+0

很好的知名度,但運行代碼時我遇到此異常: 例外:在相同的包含故事板多個動畫不能定位在相同的屬性一個單一的元素。 – user6112967