【发布时间】:2015-10-19 06:57:29
【问题描述】:
我已经为我的 UWP 应用程序创建了一个内容对话框,其中涉及一个集中的 UI 元素和周围的空白区域。但是内容对话框没有像“IsLightDismissEnabled”这样的属性来关闭对话框,单击除 UIELEMENT 区域之外的区域.我怎样才能实现它?
【问题讨论】:
我已经为我的 UWP 应用程序创建了一个内容对话框,其中涉及一个集中的 UI 元素和周围的空白区域。但是内容对话框没有像“IsLightDismissEnabled”这样的属性来关闭对话框,单击除 UIELEMENT 区域之外的区域.我怎样才能实现它?
【问题讨论】:
在内容对话框后面的代码中:
public sealed partial class CustomDialog : ContentDialog
{
public CustomDialog()
{
this.InitializeComponent();
Boolean isHide;
Window.Current.CoreWindow.PointerPressed += (s, e) =>
{
if (isHide)
Hide();
};
PointerExited += (s, e) => isHide = true;
PointerEntered += (s, e) => isHide = false;
}
}
【讨论】:
我能想到的选项很少:
示例或弹窗用法:
<Popup x:Name="MenuPopUp"
IsLightDismissEnabled="True"
HorizontalOffset="{Binding HorizontalOffset}"
VerticalOffset="{Binding VerticalOffset}"
IsOpen="{Binding IsOpen, Mode=TwoWay}">
<Grid>
YOUR ELEMENTS HERE
</Grid>
</Popup>
【讨论】:
内容对话框是一个模式对话框。为什么不使用Popup 或它的子类?它是非模态的,并且已经具有您刚才提到的 IsLightDismissEnabled 属性。
【讨论】:
<Popup x:Name="MenuPopUp"
IsLightDismissEnabled="True"
LostFocus="MenuPopUp_LostFocus"/>
In CS
private void MenuPopUp_LostFocus(object sender, RoutedEventArgs e)
{
MenuPopup.IsOpen = false;
}
【讨论】: