我需要在我的UWP应用程序中显示全屏对话框(在应用程序窗口边界中),但似乎无法使其正常工作。我尝试过:
ContentDialog仅显示使用FullSizeDesired =“True”进行垂直拉伸
弹出窗口,甚至试图将代码中的宽度和高度设置为无法正常工作
Flyout Placement =“Full”仅垂直拉伸,就像contentdialog一样
不敢相信我在这件事上花了那么多时间:(
由于
答案 0 :(得分:0)
你有没有试过这样的事情:
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
您应该会看到一个半透明的叠加层,屏幕中间有一个白色矩形。
答案 1 :(得分:0)
要使全屏弹出窗口,请执行以下操作。希望这会有所帮助。
我有一个要显示为弹出窗口的用户控件。名称为“ URLUserControl”
步骤1:UC的用户界面(仅第一位。不完整的代码)
<UserControl>
<Grid>
<Popup x:Name="MPopup" VerticalAlignment="Center">
<Grid x:Name="MainGrid">
第2步:在UC中以全局方式创建CompositeTransform。
CompositeTransform myTranslate = new CompositeTransform();
第3步: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)
{
}
}
以上代码将帮助弹出窗口成为屏幕的中心,并以全屏显示。一探究竟。编码愉快!