2017-02-24 4 views
1

私は、AppBarにページのグリッドにあるスタックパネルにボタンを追加するボタンを持っています。 新しいボタンにRightTappedイベントを割り当てました。 しかし、新しいボタンを右クリックすると、RightTappedイベントに割り当てられたメソッドを起動する代わりに、プログラムがAppBarを膨張させます。 新しいボタン以外のすべてのアイテムにIsRightTapEnabled = "False"を設定しようとしましたが、それは問題を解決しませんでした。 私は立ち往生しており、助けが必要です。ここでボタンを右クリックすると、右クリックイベントを発生させる代わりにAppBarが膨張する

は、背後に私のコードです:ここでは

public sealed partial class MainPage : Page 
{ 
    public MainPage() 
    { 
     this.InitializeComponent(); 
    } 
    int index = 0; 

    private void AppBarButton_Click(object sender, RoutedEventArgs e) 
    { 
     index++; 
     string ButtonName = "Button" + index; 
     Button dummyButton = new Button 
     { 
      Name = ButtonName, 
      Content = ButtonName, 
     }; 
     StackPanel1.Children.Add(dummyButton); 
     dummyButton.RightTapped += new RightTappedEventHandler(DummyButton_RightTapped); 
    } 

    private void Button0_RightTapped(object sender, RightTappedRoutedEventArgs e) 
    { 
     MenuFlyout myFlyout = new MenuFlyout(); 
     MenuFlyoutItem firstItem = new MenuFlyoutItem { Text = "Right Clicked" }; 

     myFlyout.Items.Add(firstItem); 
     myFlyout.ShowAt(sender as FrameworkElement); 
    } 

    private void DummyButton_RightTapped(object sender, RightTappedRoutedEventArgs e) 
    { 
     //var dialog = new MessageDialog("Right clicked"); 
     //await dialog.ShowAsync(); 

     MenuFlyout myFlyout = new MenuFlyout(); 
     MenuFlyoutItem firstItem = new MenuFlyoutItem { Text = "Right Clicked" }; 

     myFlyout.Items.Add(firstItem); 
     myFlyout.ShowAt(sender as FrameworkElement); 
    } 
} 

は私のXAMLコードは次のとおりです。

<Page 
x:Class="Soundboard.MainPage" 
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" 
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" 
xmlns:local="using:Soundboard" 
xmlns:d="http://schemas.microsoft.com/expression/blend/2008" 
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 
mc:Ignorable="d" 
IsRightTapEnabled="False"> 

<Page.TopAppBar > 
    <AppBar IsSticky="True" IsRightTapEnabled="False" > 
     <StackPanel HorizontalAlignment="Right" Orientation="Horizontal"> 
      <AppBarButton Label="Add Sound" Icon="OpenFile" Click="AppBarButton_Click" ></AppBarButton> 
     </StackPanel> 
    </AppBar> 
</Page.TopAppBar> 

<Grid Background="#FF004D40" Name="myGrid" IsRightTapEnabled="False"> 
    <Grid.RowDefinitions> 
     <RowDefinition Height="1*"/> 
     <RowDefinition Height="1*"/> 
     <RowDefinition Height="1*"/> 
     <RowDefinition Height="1*"/> 
     <RowDefinition Height="1*"/> 
     <RowDefinition Height="1*"/> 
    </Grid.RowDefinitions> 
    <StackPanel Name="StackPanel1" Grid.Row="0" Orientation="Horizontal" IsRightTapEnabled="False"> 
     <Button Content="Button0" Name ="Button0" RightTapped="Button0_RightTapped"></Button> 
    </StackPanel> 
</Grid> 

答えて

0

公式がUWPでAppBarを使用することはお勧めしません。次のセクションでは、公式AppBarの手順を参照しています。

AppBarを使用するユニバーサルWindows 8アプリケーションをアップグレードするときに、変更を最小限に抑える必要がある場合のみ、AppBarを使用する必要があります。 Windows 10の新しいアプリケーションでは、代わりにCommandBarコントロールを使用することをお勧めします。

使用

は、単にコードを次のように<Page.TopAppBar>CommandBarを追加します。

<Page.TopAppBar> 
     <CommandBar IsSticky="True"> 
      <AppBarButton 
       Click="AppBarButton_Click" 
       Icon="OpenFile" 
       Label="Add Sound" />    
     </CommandBar> 
    </Page.TopAppBar> 
関連する問題