2017-09-04 87 views
0

我有这样的代码:我如何的4行和2个按钮之间切换?

 <Grid Grid.Row="2" x:Name="buttonGrid" Padding="10,0,10,0" HorizontalOptions="FillAndExpand" VerticalOptions="Center"> 
      <Button x:Name="aButton" Style="{StaticResource pointButton}" Text="Don't Know" /> 
      <Button x:Name="bButton" Style="{StaticResource pointButton}" Text="Very Hard" /> 
      <Button x:Name="cButton" Style="{StaticResource pointButton}" Text="Hard" /> 
      <Button x:Name="dButton" Style="{StaticResource pointButton}" Text="Easy" /> 
      <Button x:Name="nButton" Style="{StaticResource pointButton}" Text="Don't Know" /> 
      <Button x:Name="yButton" Style="{StaticResource pointButton}" Text="Easy" /> 
     </Grid> 

我想有前4次或最后两个按钮出现在屏幕的连续底部。

是否有可能具有多于一个的Grid.Row =“2”,并在后端C#切换到一个或另一个具有一个ISVISIBLE?我认为这会做我所需要的,但不知道这是否是一个很好的方法来做到这一点?

我会很感激一些建议,现在我只需设置ISVISIBLE每个按钮的作用和预期不连续显示。

回答

1

你绝对可以有两个或多个网格/容器被分配到一个给定行。使用isVisible来显示/隐藏那些容纳按钮组的容器应该工作得很好。

0

你想要的是像这样

<Grid> 
    <Grid.RowDefinitions> 
     <RowDefinition Height="9*"/> 
     <RowDefinition Height="1*"/> 
    </Grid.RowDefinitions> 
    <StackLayout Orientation="Horizontal" HorizontalOptions="CenterAndExpand" Grid.Row="1" IsVisible="{Binding FirstButtons}"> 
     <Button x:Name="button1" Text="button1" Command="{Binding ChangeButtonsCommand}"/> 
     <Button x:Name="button2" Text="button2" Command="{Binding ChangeButtonsCommand}"/> 
     <Button x:Name="button3" Text="button3" Command="{Binding ChangeButtonsCommand}"/> 
     <Button x:Name="button4" Text="button4" Command="{Binding ChangeButtonsCommand}"/> 
    </StackLayout> 
    <StackLayout Orientation="Horizontal" HorizontalOptions="CenterAndExpand" Grid.Row="1" IsVisible="{Binding SecondButtons}"> 
     <Button x:Name="buttonA" Text="buttonA" Command="{Binding ChangeButtonsCommand}"/> 
     <Button x:Name="buttonB" Text="buttonB" Command="{Binding ChangeButtonsCommand}"/> 
    </StackLayout> 
</Grid> 

随着视图模型是这样的

public class MainViewModel : ViewModelBase 
{ 
    public ICommand ChangeButtonsCommand { get; private set; } 

    private bool firstButtons = true; 

    public bool FirstButtons 
    { 
     get { return firstButtons; } 
     set 
     { 
      firstButtons = value; 
      OnPropertyChanged(); 
     } 
    } 
    private bool secondButtons = false; 

    public bool SecondButtons 
    { 
     get { return secondButtons; } 
     set 
     { 
      secondButtons = value; 
      OnPropertyChanged(); 
     } 
    } 

    public MainViewModel() 
    { 
     ChangeButtonsCommand = new Command(() => 
     { 
      if (FirstButtons) 
      { 
       FirstButtons = false; 
       SecondButtons = true; 
      } 
      else 
      { 
       FirstButtons = true; 
       SecondButtons = false; 
      } 
     }); 
    } 

ViewModelBase在这里https://pastebin.com/aLMXRN50

这给了你4个按钮一行,当你按任何一个按钮时,它只切换到2个按钮。有很多方法可以做到这一点,但我认为这就是你的追求。需要注意的是Grid.Row属性在网格中的子元素,不会对电网本身的设置。