2016-11-15 110 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」頁面 –