現在開発中の 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;
}
現在、このポップアップには「閉じる」ボタンがありますが、それをタップせずに、まだ表示されている前のページで別のボタンをタップすると、新しいページに移動した後でもポップアップが残ります。ポップアップを閉じるには、[閉じる] をクリックする必要があります。
私が探しているのは、ポップアップ自体の外側をタップするとポップアップが閉じる方法です。これを行うための事前定義された方法はありますか? そうでない場合、どのような方法でそれを行うことができますか?
前もって感謝します
編集: ポップアップの 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;
}
}
}
ポップアップの 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>