[英]UWP show Fullscreen Popup, ContentDialog or Flyout
I need to display a full screen dialog (in application window boundaries) in my UWP application, but can't seems to make it work.我需要在我的 UWP 应用程序中显示一个全屏对话框(在应用程序窗口边界中),但似乎无法让它工作。 I tried with :
我试过:
ContentDialog only shows vertically stretched with FullSizeDesired="True" ContentDialog 只显示垂直拉伸 FullSizeDesired="True"
Popup, even trying to set the width and height in code behind its not working弹出窗口,甚至试图在其后面的代码中设置宽度和高度不起作用
Flyout Placement="Full" only stretch it vertically just like the contentdialog Flyout Placement="Full" 只像内容对话框一样垂直拉伸
Can't believe I spend so much time on that thing :(不敢相信我花了这么多时间在那件事上:(
Thanks谢谢
To make a popup fullscreen I did the following.为了使弹出全屏显示,我执行了以下操作。 Hope this helps.
希望这可以帮助。
I have a user control I wanted to show as a popup.我有一个想要显示为弹出窗口的用户控件。 Its name "URLUserControl"
它的名字“URLUserControl”
Step 1: UI of the UC (Just the first bit. Not complete code)第一步:UC的UI(只是第一位。不是完整的代码)
<UserControl>
<Grid>
<Popup x:Name="MPopup" VerticalAlignment="Center">
<Grid x:Name="MainGrid">
Step 2: Create a CompositeTransform in the UC as global.第 2 步:在 UC 中创建一个 CompositeTransform 作为全局。
CompositeTransform myTranslate = new CompositeTransform();
Step 3: UC constructor add the following第三步: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)
{
}
}
Above code will help the popup to be center of the screen and display in fullscreen in size.上面的代码将帮助弹出窗口位于屏幕中心并以全屏尺寸显示。 Check it out.
一探究竟。 Happy coding!
快乐编码!
Have you tried something like this: 你尝试过这样的事情:
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
You should see a semi-transparent overlay with a white rectangle in the middle of your screen. 您应该会看到一个半透明的叠加层,屏幕中间有一个白色矩形。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.