iVi*_*ikD 1 c# popup windows-phone
我有一个我正在开发的Windows Phone应用程序,我的共享按钮打开一个带有几个选项的小弹出窗口,使用以下代码:
private void share_Click(object sender, System.EventArgs e)
{
Popup share= new Popup();
share.Child = new sharePopup();
share.IsOpen = true;
share.VerticalOffset = 30;
share.HorizontalOffset = 0;
}
Run Code Online (Sandbox Code Playgroud)
现在,这个弹出窗口有一个"关闭"按钮,但是如果我不点击它,而是点击前一个仍然可见的页面上的另一个按钮,即使在移动到新页面之后,弹出窗口也会保持原位.我必须点击"关闭"弹出窗口才能消失.
如果我点击弹出窗口之外的任何地方,我正在寻找的方法是关闭弹出窗口.是否有预定义的方法来执行此操作?如果没有,我可以采取哪些方式?
提前致谢
编辑:这是弹出窗口的c#代码
public partial class sharePopup : UserControl
{
public sharePopup()
{
InitializeComponent();
}
private void Button_Click(object sender, RoutedEventArgs e)
{
Popup mensaje = this.Parent as Popup;
mensaje.IsOpen = false;
}
private void UserControl_Loaded(object sender, RoutedEventArgs e)
{
this.Focus();
}
private void UserControl_LostFocus(object sender, RoutedEventArgs e)
{
Popup mensaje = this.Parent as Popup;
mensaje.IsOpen = false;
}
}
Run Code Online (Sandbox Code Playgroud)
}
弹出窗口的XAML仅包含大小,颜色和按钮定义:
<UserControl x:Class="MSPinTrainingApp.sharePopup"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
mc:Ignorable="d"
FontFamily="{StaticResource PhoneFontFamilyNormal}"
FontSize="{StaticResource PhoneFontSizeNormal}"
Foreground="{StaticResource PhoneForegroundBrush}"
d:DesignHeight="480" d:DesignWidth="480"
Width="480" Height="200" >
<Grid x:Name="LayoutRoot" LostFocus="LayoutRoot_LostFocus">
<Grid.RowDefinitions>
<RowDefinition Height="auto"/>
<RowDefinition Height="*"/>
<RowDefinition Height="*"/>
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="auto"/>
<ColumnDefinition Width="*"/>
<ColumnDefinition Width="*"/>
</Grid.ColumnDefinitions>
<Grid.Background>
<SolidColorBrush Color="{StaticResource PhoneChromeColor}"/>
</Grid.Background>
<TextBlock HorizontalAlignment="Stretch" VerticalAlignment="Stretch"
Margin="3" x:Name="txtMensaje" Text="Compartir:" LostFocus="txtMensaje_LostFocus" />
<Image Margin="70,60,335,62" Source="appbar.email.hardedge.png" Stretch="Fill" Tap="Image_Tap_1"/>
<Image Margin="200,60,200,62" Source="appbar.facebook.png" Stretch="Fill" Tap="Image_Tap_2"/>
<Image Margin="335,60,70,62" Source="appbar.twitter.bird.png" Stretch="Fill" Tap="Image_Tap_3"/>
<Image Margin="430,-12,11,134" Source="/appbar.close.png" Width="50" Tap="Image_Tap_4"/>
</Grid>
Run Code Online (Sandbox Code Playgroud)