2016-11-15 92 views
0

我有一个使用以下XAML的Xamarin.Forms应用程序。显示用户在Xamarin表单上按下按钮时的按钮列表

<StackLayout Grid.RowSpan="8" 
        Grid.Column="0" 
        > 
      <Label Text="{Binding ActiveMenu.ChildMenuItems.Count}" /> 
     <ListView x:Name="weapponType" 
        ItemsSource="{Binding ActiveMenu.ChildMenuItems}" 
        BackgroundColor="Blue" 
       > 
      <ListView.ItemTemplate> 
      <DataTemplate> 
       <ViewCell > 
        <Button Text="{Binding Text}" 
          FontSize="14" 
          /> 
       </ViewCell> 
      </DataTemplate> 
      </ListView.ItemTemplate> 

     </ListView> 
     </StackLayout> 

它显示按钮的列表如下

---- EVENT 
-----PROG 
-----STAT 
-----MENU1 
-----MENU2 

当用户点击EVENT我希望它显示按钮

---Button1 
---Button2 
---Button3 

一个列表,其中

<Button x:Name="MenuBtn1" Text="Btn1" Command="{Binding Command1}" 
<Button x:Name="MenuBtn2" Text="Btn2" Command="{Binding Command2}" 
<Button x:Name="MenuBtn3" Text="Btn3" Command="{Binding Command3}" 

这将是重新如果有人能够指导我如何实现这一目标,那么盟友就很好。

+0

您可能(可能)想要创建第二页,并且当用户单击第一页上的按钮时,导航到第二页。 – Jason

+0

@我该怎么做? – liv2hak

+0

https://developer.xamarin.com/guides/xamarin-forms/user-interface/navigation/hierarchical/ – Jason

回答

0

u需要添加单击事件“OnBtClick”为每个按钮如下代码:

<ListView ItemsSource="{x:Static local:ListViewMode.All}" RowHeight="100"> 
    <ListView.ItemTemplate> 
     <DataTemplate> 
     <ViewCell> 
      <ViewCell.View> 
      <Button Text="{Binding BtName}" Clicked="OnBtClick"></Button> 
      </ViewCell.View> 
     </ViewCell> 
     </DataTemplate> 
    </ListView.ItemTemplate> 
    </ListView> 

在后面的代码:

async void OnBtClick(object sender, EventArgs e) 
     { 
      await Navigation.PushAsync(new ContentPage 
      { 
       Content = new StackLayout 
       { 
        VerticalOptions = LayoutOptions.Center, 
        Children = { 
         new Button { 

          Text = "button1" 
         }, 
         new Button { 

          Text = "button2" 
         }, 
         new Button { 

          Text = "button3" 
         } 
        } 
       } 
      }); 
     } 

当你点击每个按钮,将显示三个我在上面定义的按钮。

+0

“新的Contantpage()”可以是您定义的任何“.xmal”页面 –