Windows phone 8.1 Flyout 隐藏行为问题 [英] Windows phone 8.1 Flyout hide with behaviour issue

查看:20
本文介绍了Windows phone 8.1 Flyout 隐藏行为问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

以下行为 xaml 有什么问题,在运行时没有任何反应(甚至没有异常).我试图在没有逻辑背后的代码的情况下关闭弹出窗口.

What's wrong with the following behavior xaml , nothing happens at run time ( not even a exception). I'm trying to close flyout without code behind logic.

<AppBarButton HorizontalAlignment="Left"
                          Label="Pin to dashboard"
                          x:Name="pinBtn">
                <AppBarButton.Flyout>
                    <Flyout x:Name="flyout"
                            Placement="Full">
                        <StackPanel x:Name="stackPanel"
                                    HorizontalAlignment="Center"
                                    VerticalAlignment="Top">
                            <TextBlock Text="Save as"
                                       HorizontalAlignment="Center"
                                       FontSize="16" />
                            <TextBox Width="275"
                                     Style="{StaticResource RoundedTextBox}"
                                     FontFamily="Global User Interface" />
                            <StackPanel Orientation="Horizontal"
                                        HorizontalAlignment="Center">
                                <Button Content="Save"
                                        Width="50" />
                                <Button x:Name="button"
                                        Content="Cancel"
                                        Width="50"
                                        Margin="10,0,0,0">
                                     <Interactivity:Interaction.Behaviors>
                                        <Core:EventTriggerBehavior x:Name="eventTriggerBehavior" EventName="Click">
                                            <Core:CallMethodAction TargetObject="{Binding Flyout, ElementName=pinBtn}"
                                                                   MethodName="Hide" />
                                        </Core:EventTriggerBehavior>
                                    </Interactivity:Interaction.Behaviors>
                                </Button>
                            </StackPanel>
                        </StackPanel>
                    </Flyout>
                </AppBarButton.Flyout>
            </AppBarButton>

推荐答案

我最近写了 一篇博文,介绍如何通过自定义行为或操作实现此目的.

I recently wrote a blog post on how you can accomplish this with a custom behavior or action.

当按钮被点击时,你会想要沿着可视化树向上走,直到你找到 FlyoutPresenter,然后将它的 Parent 作为弹出窗口并将 IsOpen 设置为 false;

When the button is clicked, you'll want to walk up the visual tree until you find the FlyoutPresenter, then get it's Parent as a popup and set IsOpen to false;

var flyout = element.GetVisualParent<FlyoutPresenter>();
if (flyout != null)
{
    var popup = flyout.Parent as Popup;
    if (popup != null)
    {
        popup.IsOpen = false;
    }
}

这篇关于Windows phone 8.1 Flyout 隐藏行为问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆