[英]UWP show Fullscreen Popup, ContentDialog or Flyout
我需要在我的 UWP 应用程序中显示一个全屏对话框(在应用程序窗口边界中),但似乎无法让它工作。 我试过:
ContentDialog 只显示垂直拉伸 FullSizeDesired="True"
弹出窗口,甚至试图在其后面的代码中设置宽度和高度不起作用
Flyout Placement="Full" 只像内容对话框一样垂直拉伸
不敢相信我花了这么多时间在那件事上:(
谢谢
为了使弹出全屏显示,我执行了以下操作。 希望这可以帮助。
我有一个想要显示为弹出窗口的用户控件。 它的名字“URLUserControl”
第一步:UC的UI(只是第一位。不是完整的代码)
<UserControl>
<Grid>
<Popup x:Name="MPopup" VerticalAlignment="Center">
<Grid x:Name="MainGrid">
第 2 步:在 UC 中创建一个 CompositeTransform 作为全局。
CompositeTransform myTranslate = new CompositeTransform();
第三步:UC构造函数添加以下内容
private void InitURLUserControl()
{
MPopup.IsOpen = true;
Window.Current.SizeChanged += Current_SizeChanged;
MainGrid.Width = Window.Current.Bounds.Width;
MainGrid.Height = Window.Current.Bounds.Height;
myTranslate.TranslateY = (int)(Window.Current.Bounds.Height - MainGrid.Height) / 2
}
private void Current_SizeChanged(object sender, WindowSizeChangedEventArgs e)
{
try
{
MainGrid.Width = Window.Current.Bounds.Width;
MainGrid.Height = Window.Current.Bounds.Height;
}
catch (Exception ex)
{
}
}
上面的代码将帮助弹出窗口位于屏幕中心并以全屏尺寸显示。 一探究竟。 快乐编码!
你尝试过这样的事情:
var c = Window.Current.Bounds;
var g = new Grid
{
Width = c.Width,
Height = c.Height,
Background = new SolidColorBrush(Color.FromArgb(0x20, 0, 0, 0)),
Children =
{
new Rectangle
{
Width = 100,
Height = 100,
Fill = new SolidColorBrush(Colors.White),
Stroke = new SolidColorBrush(Colors.Black),
StrokeThickness = 3
}
}
};
var p = new Popup
{
HorizontalOffset = 0,
VerticalOffset = 0,
Width = c.Width,
Height = c.Height,
Child = g
};
p.IsOpen = true; // open when ready
您应该会看到一个半透明的叠加层,屏幕中间有一个白色矩形。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.