IsLightDismissEnabled ="真"实际上并没有解雇弹出窗口

时间:2015-03-28 10:28:25

标签: c# windows-store-apps windows-8.1

我有一个弹出窗口,当我点击弹出窗口外的任何地方时我想关闭它。我搜索过,大家都建议我使用属性IsLightDismissEnabled;然而,如果我在外面触摸,它只会移除流行音乐,使所有内容处于非活动状态,并且像灰色屏幕一样,就像它没有完全关闭弹出窗口一样 这是我的代码片段:

 <Popup x:Name="logincontroler" IsOpen="False" Margin="0,190,896,276" IsLightDismissEnabled="True">
            <StackPanel Height="300" Width="470" x:Name="popup" FlowDirection="RightToLeft">
                <Grid Width="470" Background="White" >
                    <Grid.RowDefinitions>
                        <RowDefinition Height="70"/>
                        <RowDefinition Height="*"/>
                    </Grid.RowDefinitions>
                    <RichEditBox Grid.Row="1" Height="250" TextWrapping="Wrap" FontSize="20" Name="notesPopupTextBox" FlowDirection="LeftToRight"/>
                    <StackPanel Grid.Row="0" Orientation="Horizontal" Background="#FFE3E3E5">
                        <Button Name="CanclePopupButton" Content="Cancel" Width="64" Height="64" Click="CanclePopupButton_Click" />
                        <Button Name="ClearNotePopupButton" Content="Clear" Width="64" Height="64" Click="ClearNotePopupButton_Click" />
                        <Button Name="saveNoteButton" Content="Save" Width="64" Height="64" Click="saveNoteButton_Click" />

                        <TextBlock FontWeight="Medium"  FontSize="40" Foreground="#2a2a86" Margin="170 12 0 0">Note</TextBlock>
                    </StackPanel>
                </Grid>
            </StackPanel>
        </Popup>

这是我的事件代码

 private void ShowButton_Click(object sender, RoutedEventArgs e)
    {
        logincontroler.IsOpen = true;
        flipView1.IsEnabled = false;
    }
    private void CanclePopupButton_Click(object sender, RoutedEventArgs e)
    {
        logincontroler.IsOpen = false;
        flipView1.IsEnabled = true;
    }

我错过了什么吗? 提前谢谢你

1 个答案:

答案 0 :(得分:1)

您确定在应用中没有其他代码,但您没有向我们展示吗? Popup后面不应该有格雷框 我刚刚在一个空的Windows 8.1(XAML + C#)应用程序上测试了你的代码,它运行正常。

尝试创建和删除Windows 8.1应用程序并使您像这样使用MainPage:

MainPage.xaml

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

    <Grid Background="{ThemeResource ApplicationPageBackgroundThemeBrush}">
        <Popup x:Name="logincontroler" IsOpen="False" Margin="0,190,896,276" IsLightDismissEnabled="True">
            <StackPanel Height="320" Width="470" x:Name="popup" FlowDirection="RightToLeft">
                <Grid Width="470" Background="BurlyWood" >
                    <Grid.RowDefinitions>
                        <RowDefinition Height="70"/>
                        <RowDefinition Height="*"/>
                    </Grid.RowDefinitions>
                    <RichEditBox Grid.Row="1" Height="250" TextWrapping="Wrap" FontSize="20" Name="notesPopupTextBox" FlowDirection="LeftToRight"/>
                    <StackPanel Grid.Row="0" Orientation="Horizontal" Background="#FFE3E3E5">
                        <Button Name="CanclePopupButton" Content="Cancel" Width="64" Height="64" />
                        <Button Name="ClearNotePopupButton" Content="Clear" Width="64" Height="64" />
                        <Button Name="saveNoteButton" Content="Save" Width="64" Height="64" />

                        <TextBlock FontWeight="Medium"  FontSize="40" Foreground="#2a2a86" Margin="170 12 0 0">Note</TextBlock>
                    </StackPanel>
                </Grid>
            </StackPanel>
        </Popup>
        <Button Content="Show Popup" HorizontalAlignment="Left" Margin="692,260,0,0" VerticalAlignment="Top" Click="ShowButton_Click"/>
    </Grid>
</Page>

MainPage.xaml.cs

using Windows.UI.Xaml;
using Windows.UI.Xaml.Controls;

namespace App19
{
    /// <summary>
    /// An empty page that can be used on its own or navigated to within a Frame.
    /// </summary>
    public sealed partial class MainPage : Page
    {
        public MainPage()
        {
            this.InitializeComponent();
        }

        private void ShowButton_Click(object sender, RoutedEventArgs e)
        {
            logincontroler.IsOpen = true;
        }
    }
}

这必须奏效 将此与您的解决方案进行比较可以帮助您找到问题所在。如果没有,请使用更多信息编辑您的问题。 (更多代码)

  

注意:我从弹出窗口中删除了点击事件,不需要它们来举例说明您的问题,对吗?