如何忽略按钮以捕获我们在 Template10 中忽略的按钮内的按钮点击?

How to ignore button to capture click of buttons inside the button that we ignore in Template10?

我想单击模板 10 HamburgerMenu 文本按钮内的组合框。我该怎么做。

<Controls:HamburgerMenu x:Name="MyHamburgerMenu" PaneWidth="272">

    <Controls:HamburgerMenu.PrimaryButtons>
        <!--  user potrait  -->
        <Controls:HamburgerButtonInfo ButtonType="Literal" ClearHistory="True">
            <RelativePanel Margin="52,4,12,4">
                <Ellipse
                    x:Name="Potrait"
                    Width="100"
                    Height="100"
                    Margin="4"
                    RelativePanel.AlignLeftWithPanel="True"
                    RelativePanel.AlignRightWithPanel="True"
                    RelativePanel.AlignTopWithPanel="True"
                    Stroke="Black">
                    <Ellipse.Fill>
                        <ImageBrush ImageSource="ms-appx:///Assets/child potrait.jpg" Stretch="UniformToFill" />
                    </Ellipse.Fill>
                </Ellipse>
                <ComboBox
                    x:Name="User"
                    Margin="4"
                    HorizontalAlignment="Stretch"
                    RelativePanel.AlignLeftWithPanel="True"
                    RelativePanel.AlignRightWithPanel="True"
                    RelativePanel.Below="Potrait">
                    <ComboBoxItem Content="Amir" IsSelected="True" />
                    <ComboBoxItem Content="Aishah" />
                    <ComboBoxItem Content="Alia" />
                </ComboBox>
                <ComboBox
                    Margin="4"
                    HorizontalAlignment="Stretch"
                    RelativePanel.AlignLeftWithPanel="True"
                    RelativePanel.AlignRightWithPanel="True"
                    RelativePanel.Below="User">
                    <ComboBoxItem Content="Matematik" IsSelected="True" />
                    <ComboBoxItem Content="Bahasa Malaysia" />
                    <ComboBoxItem Content="Bahasa Inggeris" />
                </ComboBox>
            </RelativePanel>
        </Controls:HamburgerButtonInfo>

http://i.imgur.com/HZoLC1P.png

我想点击肖像下的组合框。现在,当我点击肖像附近的任何地方(包括组合框)时,汉堡包窗格会折叠。

谢谢。

when i click anywhere near the potrait(including the combobox), hamburger pane collapse.

上面描述的"issue"是HamburgerMenu在Template 10中的特性。following code简单的解释了这个特性。

var escape = new Func<bool>(() =>
{
  if (DisplayMode == SplitViewDisplayMode.CompactOverlay
      || DisplayMode == SplitViewDisplayMode.Overlay)
        IsOpen = false;
    if (Equals(ShellSplitView.PanePlacement, SplitViewPanePlacement.Left))
     {
          ShellSplitView.Content.RenderTransform = new TranslateTransform { X = 48 + ShellSplitView.OpenPaneLength };
           focus(FocusNavigationDirection.Right);
           ShellSplitView.Content.RenderTransform = null;
         }
             else
        {
           ShellSplitView.Content.RenderTransform = new TranslateTransform { X = -48 - ShellSplitView.OpenPaneLength };
           focus(FocusNavigationDirection.Left);
           ShellSplitView.Content.RenderTransform = null;
       }
     return true;
});

当您触摸汉堡包内容以折叠汉堡包窗格时,将执行退出功能。

我已经尝试通过将 IsOpen 设置为 true 来直接处理您的问题,而您的组合框 PointerEntered 就像下面的代码一样。

private bool canCloseHamburgerMenu = true;
private void User_PointerEntered(object sender, Windows.UI.Xaml.Input.PointerRoutedEventArgs e)
{
    canCloseHamburgerMenu = false;
}

private void User_PointerExited(object sender, Windows.UI.Xaml.Input.PointerRoutedEventArgs e)
{
    canCloseHamburgerMenu = true;
}

private void MyHamburgerMenu_IsOpenChanged(object sender, ChangedEventArgs<bool> e)
{
    var hm = sender as HamburgerMenu;
    if ((hm.DisplayMode == SplitViewDisplayMode.CompactOverlay || hm.DisplayMode == SplitViewDisplayMode.Overlay) && e.NewValue == false)
    {
        //hm.IsOpen = canCloseHamburgerMenu == false ? true : false;
    }
}

但是它抛出堆栈溢出异常。我在 source code.

中找到了原因
partial void InternalIsOpenChanged(ChangedEventArgs<bool> e)
{
    UpdateIsPaneOpen(e.NewValue);
    UpdateHamburgerButtonGridWidthToFillAnyGap();
    UpdateControl();
}

当我更改 IsOpen 属性 时,将执行 InternalIsOpenChanged 方法并将 IsOpen 重置为 false 然后 MyHamburgerMenu_IsOpenChanged 事件将被激活。所以线程进入无限循环。

HamburgerMenu的class被封了。所以你不能继承和重写它的方法。您可以使用 SplitView 自定义新的 hamburgerMenu。