2016-04-07 8 views
0

メインフォームからのUserControl上_multiple_タップイベントをキャプチャ(XAML)昨日答えたこの質問を参照する

How to capture tap event on specific button in user control from main form

が、私は今、私は、「ダッシュボード」のUserControlを持っている問題に直面しています複数のタップイベントを同じユーザーコントロールに追加する必要があります。

何が起こっているのですが、最初のタップイベントだけが発生しているようです。

ヘルプ?

(ページ03が問題の一つです)

のMainForm:

public MainPage() { 
     InitializeComponent(); 

     Page02.CloseButtonTapped += Page02_CloseButtonTapped; 
     Page03.CloseButtonTapped += Page03_CloseButtonTapped; 
     Page11.CloseButtonTapped += Page11_CloseButtonTapped; 

     Page03.CommandControlTapped += Page03_CommandControlTapped; 

    } 

page03:

public delegate void CloseButtonTappedHandler(object sender, TappedRoutedEventArgs e); 
public delegate void CommandControlTappedHandler(object sender, TappedRoutedEventArgs e); 

public sealed partial class Page03 : UserControl { 
    public event CloseButtonTappedHandler CloseButtonTapped; 
    public event CommandControlTappedHandler CommandControlTapped; 

    public Page03() { 
     this.InitializeComponent(); 

     this.imgCloseButton.Tapped += new TappedEventHandler(this.imgCloseButton_Tapped); 
     this.imgTraining.Tapped += new TappedEventHandler(this.imgTraining_Tapped); 
     this.imgCommandControl.Tapped += new TappedEventHandler(this.imgCommandControl_Tapped); 
    } 

    private void imgCloseButton_Tapped(object sender, TappedRoutedEventArgs e) { 
     if (CloseButtonTapped != null) { 
      CloseButtonTapped(sender, e); 
     } 
    } 

    private void imgCommandControl_Tapped(object sender, TappedRoutedEventArgs e) { 
     if (CommandControlTapped != null) { 
      CommandControlTapped(sender, e); 
     } 
    } 

    private void imgTraining_Tapped(object sender, TappedRoutedEventArgs e) { 
     if (CommandControlTapped != null) { 
      CommandControlTapped(sender, e); 
     } 
    } 
} 

Page03ユーザーコントロールのXAML:(レイアウト原料の束が、そこにあります線の形状など)

<UserControl 
x:Class="Raytheon.Page03" 
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" 
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" 
xmlns:local="using:Raytheon" 
xmlns:d="http://schemas.microsoft.com/expression/blend/2008" 
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 
mc:Ignorable="d" 
d:DesignHeight="918" 
d:DesignWidth="1818" Background="Gray"> 
<Grid> 
    <Rectangle HorizontalAlignment="Left" Height="48" Margin="625,416,0,0" StrokeThickness="3" VerticalAlignment="Top" Width="557" Opacity="0.5"> 
     <Rectangle.Fill> 
      <SolidColorBrush Color="White" Opacity="0.85"/> 
     </Rectangle.Fill> 
    </Rectangle> 
    <Rectangle HorizontalAlignment="Left" Height="1457.34" Margin="896.467,-53.724,0,-485.616" VerticalAlignment="Top" Width="9" Opacity="0.5" StrokeThickness="3" RenderTransformOrigin="0.5,0.5" UseLayoutRounding="False" d:LayoutRounding="Auto"> 
     <Rectangle.RenderTransform> 
      <CompositeTransform Rotation="-90" ScaleX="-1"/> 
     </Rectangle.RenderTransform> 
     <Rectangle.Fill> 
      <SolidColorBrush Color="White" Opacity="0.85"/> 
     </Rectangle.Fill> 
    </Rectangle> 
    <Rectangle HorizontalAlignment="Left" Height="1457.345" Margin="896.467,-523.224,0,-16.121" VerticalAlignment="Top" Width="9" Opacity="0.5" StrokeThickness="3" RenderTransformOrigin="0.5,0.5" UseLayoutRounding="False" d:LayoutRounding="Auto"> 
     <Rectangle.RenderTransform> 
      <CompositeTransform Rotation="-90" ScaleX="-1"/> 
     </Rectangle.RenderTransform> 
     <Rectangle.Fill> 
      <SolidColorBrush Color="White" Opacity="0.85"/> 
     </Rectangle.Fill> 
    </Rectangle> 
    <Rectangle HorizontalAlignment="Left" Height="478" Margin="396,201,0,0" VerticalAlignment="Top" Width="9" Opacity="0.5" StrokeThickness="3"> 
     <Rectangle.Fill> 
      <SolidColorBrush Color="White" Opacity="0.85"/> 
     </Rectangle.Fill> 
    </Rectangle> 
    <Image x:Name="image" HorizontalAlignment="Left" Height="72" Margin="665,404,0,0" VerticalAlignment="Top" Width="467" Source="Assets/1920x1080_TailoredSolutions.png"/> 
    <Image x:Name="image1" HorizontalAlignment="Left" Height="69" Margin="126,296,0,0" VerticalAlignment="Top" Width="249" Source="Assets/1920x1080_Text_Training.png"/> 
    <Rectangle HorizontalAlignment="Left" Height="228" Margin="506.55,325.193,0,0" VerticalAlignment="Top" Width="9" Opacity="0.5" StrokeThickness="3" RenderTransformOrigin="0.5,0.5" UseLayoutRounding="False" d:LayoutRounding="Auto"> 
     <Rectangle.RenderTransform> 
      <CompositeTransform Rotation="-90" ScaleX="-1"/> 
     </Rectangle.RenderTransform> 
     <Rectangle.Fill> 
      <SolidColorBrush Color="White" Opacity="0.85"/> 
     </Rectangle.Fill> 
    </Rectangle> 
    <Rectangle HorizontalAlignment="Left" Height="478" Margin="1402,201,0,0" VerticalAlignment="Top" Width="9" Opacity="0.5" StrokeThickness="3"> 
     <Rectangle.Fill> 
      <SolidColorBrush Color="White" Opacity="0.85"/> 
     </Rectangle.Fill> 
    </Rectangle> 
    <Rectangle HorizontalAlignment="Left" Height="228" Margin="1291.55,325.193,0,0" VerticalAlignment="Top" Width="9" Opacity="0.5" StrokeThickness="3" RenderTransformOrigin="0.5,0.5" UseLayoutRounding="False" d:LayoutRounding="Auto"> 
     <Rectangle.RenderTransform> 
      <CompositeTransform Rotation="-90" ScaleX="-1"/> 
     </Rectangle.RenderTransform> 
     <Rectangle.Fill> 
      <SolidColorBrush Color="White" Opacity="0.85"/> 
     </Rectangle.Fill> 
    </Rectangle> 
    <Rectangle HorizontalAlignment="Left" Height="214" Margin="1076,201,0,0" VerticalAlignment="Top" Width="9" Opacity="0.5" StrokeThickness="3"> 
     <Rectangle.Fill> 
      <SolidColorBrush Color="White" Opacity="0.85"/> 
     </Rectangle.Fill> 
    </Rectangle> 
    <Rectangle HorizontalAlignment="Left" Height="214" Margin="1076,466,0,0" VerticalAlignment="Top" Width="9" Opacity="0.5" StrokeThickness="3"> 
     <Rectangle.Fill> 
      <SolidColorBrush Color="White" Opacity="0.85"/> 
     </Rectangle.Fill> 
    </Rectangle> 
    <Rectangle HorizontalAlignment="Left" Height="214" Margin="731,201,0,0" VerticalAlignment="Top" Width="9" Opacity="0.5" StrokeThickness="3"> 
     <Rectangle.Fill> 
      <SolidColorBrush Color="White" Opacity="0.85"/> 
     </Rectangle.Fill> 
    </Rectangle> 
    <Rectangle HorizontalAlignment="Left" Height="214" Margin="731,466,0,0" VerticalAlignment="Top" Width="9" Opacity="0.5" StrokeThickness="3"> 
     <Rectangle.Fill> 
      <SolidColorBrush Color="White" Opacity="0.85"/> 
     </Rectangle.Fill> 
    </Rectangle> 
    <Image x:Name="imgCloseButton" HorizontalAlignment="Left" Height="111" Margin="1669,30,0,0" VerticalAlignment="Top" Width="111" Source="Assets/CloseButton.png" Tapped="imgCloseButton_Tapped"/> 
    <Image x:Name="txtSustainment" HorizontalAlignment="Left" Height="69" Margin="439,296,0,0" VerticalAlignment="Top" Width="249" Source="Assets/1920x1080_Text_Sustainment.png"/> 
    <Image x:Name="txtCommunicaton" HorizontalAlignment="Left" Height="69" Margin="1134,296,0,0" VerticalAlignment="Top" Width="249" Source="Assets/1920x1080_Text_Communications.png"/> 
    <Image x:Name="txtFixedSensors" HorizontalAlignment="Left" Height="69" Margin="1438,296,0,0" VerticalAlignment="Top" Width="249" Source="Assets/1920x1080_Text_FixedSensors.png"/> 
    <Image x:Name="txtPhysicalSecurity" HorizontalAlignment="Left" Height="86" Margin="1438,775,0,0" VerticalAlignment="Top" Width="270" Source="Assets/1920x1080_Text_PhysicalSecurity.png"/> 
    <Image x:Name="txtPlatformUpgrades" HorizontalAlignment="Left" Height="88" Margin="1132,773,0,0" VerticalAlignment="Top" Width="279" Source="Assets/1920x1080_Text_PlatformUpgrades.png"/> 
    <Image x:Name="txtDataAnalytics" HorizontalAlignment="Left" Height="88" Margin="783,773,0,0" VerticalAlignment="Top" Width="279" Source="Assets/1920x1080_Text_DataAnalytics.png"/> 
    <Image x:Name="txtDistributedSensors" HorizontalAlignment="Left" Height="69" Margin="439,763,0,0" VerticalAlignment="Top" Width="249" Source="Assets/1920x1080_Text_DistributedSensors.png"/> 
    <Image x:Name="txtMobileSensors" HorizontalAlignment="Left" Height="69" Margin="126,763,0,0" VerticalAlignment="Top" Width="249" Source="Assets/1920x1080_Text_MobileSensors.png"/> 
    <Image x:Name="txtCommandControl" HorizontalAlignment="Left" Height="69" Margin="783,296,0,0" VerticalAlignment="Top" Width="249" Source="Assets/1920x1080_Text_CommandControl.png"/> 

    <Image x:Name="imgTraining" HorizontalAlignment="Left" Height="224" Margin="128,94,0,0" VerticalAlignment="Top" Width="234" Source="Assets/1920x1080_Icon_Training.png" Tapped="imgTraining_Tapped"/> 
    <Image x:Name="imgSustainment" HorizontalAlignment="Left" Height="224" Margin="441,94,0,0" VerticalAlignment="Top" Width="234" Source="Assets/1920x1080_Icon_Sustainment.png"/> 
    <Image x:Name="imgCommunications" HorizontalAlignment="Left" Height="224" Margin="1136,94,0,0" VerticalAlignment="Top" Width="234" Source="Assets/1920x1080_Icon_Communications.png"/> 
    <Image x:Name="imgMobileSensors" HorizontalAlignment="Left" Height="224" Margin="128,561,0,0" VerticalAlignment="Top" Width="234" Source="Assets/1920x1080_Icon_MobileSensors.png"/> 
    <Image x:Name="imgDistributedSensors" HorizontalAlignment="Left" Height="224" Margin="441,561,0,0" VerticalAlignment="Top" Width="234" Source="Assets/1920x1080_Icon_DistributedSensors.png"/> 
    <Image x:Name="imgDataAnalytics" HorizontalAlignment="Left" Height="224" Margin="785,561,0,0" VerticalAlignment="Top" Width="234" Source="Assets/1920x1080_Icon_DataAnalytics.png"/> 
    <Image x:Name="imgPlatformUpgrades" HorizontalAlignment="Left" Height="224" Margin="1136,561,0,0" VerticalAlignment="Top" Width="234" Source="Assets/1920x1080_Icon_PlatformUpgrades.png"/> 
    <Image x:Name="imgFixedSensors" HorizontalAlignment="Left" Height="224" Margin="1440,94,0,0" VerticalAlignment="Top" Width="234" Source="Assets/1920x1080_Icon_FixedSensors.png"/> 
    <Image x:Name="imgPhysicalSecurity" HorizontalAlignment="Left" Height="224" Margin="1440,561,0,0" VerticalAlignment="Top" Width="234" Source="Assets/1920x1080_Icon_PhysicalSecurity.png"/> 
    <Image x:Name="imgCommandControl" HorizontalAlignment="Left" Height="224" Margin="785,94,0,0" VerticalAlignment="Top" Width="234" Source="Assets/1920x1080_Icon_CommandControl.png" Tapped="imgCommandControl_Tapped"/> 
</Grid> 
</UserControl> 
+0

ここにいる人はここにいます。 @ oppassum、お手伝いできますか?興味深いもの: – mdrussell0779

答えて

0

Page03のイベントをMainPageで個別に登録し、新しいHandlerを作成しないでください。以下を参照してください。

Page03.CloseButtonTapped += MethodToHandleEvent 
Page03.Page11Tapped += MethodToHandleEvent 

AddHandlerを呼び出す行がイベントの新しいハンドラを登録していますが、これが混乱の原因になっていると思います。ここでイベントについてもう少し詳しくお読みください:https://msdn.microsoft.com/en-us/library/ms742806(v=vs.100).aspx

+0

私はこのように行った: 'Page02.CloseButtonTapped + = Page02_CloseButtonTapped; Page03.CloseButtonTapped + = Page03_CloseButtonTapped;Page11.CloseButtonTapped + = Page11_CloseButtonTapped; Page03.Page11Tapped + = imgCommandControl_Tapped; ' 閉じるボタンイベントのみが発生しています。 – mdrussell0779

+0

私はちょうど、メインフォームまで何もバブリングせずにそのイメージにメッセージボックスイベントをつけようとしましたが、それは発砲していないので、今私は非常に混乱しています:) – mdrussell0779

+0

Page11TappedイベントはPage03コントロールから起動していますか?デバッグし、Page03から正しく発射されていることを確認し、MainPageで正しく処理されていることを確認する必要があります。 – momar

0

私はそれを理解しました。

<local:Page01 Margin="53,156,8,10" x:Name="Page01" /> 
    <local:Page02 Margin="53,156,8,30" x:Name="Page02" Opacity="0"/> 
    <local:Page11 Margin="53,156,8,30" x:Name="Page11" Opacity="0"/> 
    <local:Page03 Margin="53,156,8,30" x:Name="Page03" Opacity="0"/> 

ので、私は11ページと3ページの順番を入れ替え、それが仕事を始めた:どのように私は、ユーザーコントロールを表示/非表示していますが、不透明度を変更することを経由しているためです。これで、ストーリーボードのアニメーションを保持しながらユーザーコントロールを表示/非表示にする必要がありますが、実際には表示されず/折りたたまれていることに対して実際には隠されていません。

+0

問題を解決したことをうれしく思います。注文が正しいことを確認するためにCanvas.ZIndexを調べることをお勧めします。詳細はこちらを参照してください。https://blogs.msdn.microsoft.com/wpfsdk/2006/06/13/controlling-z-order-using-the-zindex-property/ – momar

関連する問題