UWP show Fullscreen Popup, ContentDialog or Flyout

穿精又带淫゛_ 提交于 2019-12-12 11:03:58

问题


I need to display a full screen dialog (in application window boundaries) in my UWP application, but can't seems to make it work. I tried with :

  • ContentDialog only shows vertically stretched with 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

Can't believe I spend so much time on that thing :(

Thanks


回答1:


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.




回答2:


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"

Step 1: UI of the UC (Just the first bit. Not complete code)

<UserControl>
<Grid>
    <Popup x:Name="MPopup" VerticalAlignment="Center">
        <Grid x:Name="MainGrid">

Step 2: Create a CompositeTransform in the UC as global.

CompositeTransform myTranslate = new CompositeTransform();

Step 3: UC constructor add the following

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!



来源:https://stackoverflow.com/questions/46739337/uwp-show-fullscreen-popup-contentdialog-or-flyout

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!