1

I have tried to set the width and also min height and min width but still the dialogue wont change to full screen. tried window.bounds too but teh dialog wont expand beyond a fixed width.

    public sealed partial class ContentDialog1 : ContentDialog
{
    public ContentDialog1()
    {
        this.InitializeComponent();
        this.MinWidth = Window.Current.Bounds.Width;
    }

    private void ContentDialog_PrimaryButtonClick(ContentDialog sender, ContentDialogButtonClickEventArgs args)
    {
    }

    private void ContentDialog_SecondaryButtonClick(ContentDialog sender, ContentDialogButtonClickEventArgs args)
    {
    }


}

}

<ContentDialog
x:Class="PowerUp.UWP.View.ContentDialog1"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="using:PowerUp.UWP.View"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
mc:Ignorable="d"
Title="TITLE"
PrimaryButtonText="Button1"
SecondaryButtonText="Button2"
PrimaryButtonClick="ContentDialog_PrimaryButtonClick"
SecondaryButtonClick="ContentDialog_SecondaryButtonClick"
MinWidth ="2000">
<Grid x:Name="cd1" >
</Grid>

This is what I want

This is how content dialog is shown in my application

sadik
  • 107
  • 10
  • ContentDialogeis supposed to remain in center of the screen, u can change its height as per content but not the width – Muhammad Touseef Aug 30 '18 at 16:18
  • explain your scenario a bit more so I can suggest you an alternative way of doing this. – Muhammad Touseef Aug 30 '18 at 16:19
  • I need a page top of another like a full screen contentdialog something like the image i have added now in the question. would love if you can help – sadik Aug 30 '18 at 16:55
  • you can just use a simple grid on the same page stretch it to full screen and keep its visibility to collapsed, and whenever you want to show it set its visibility to visible and so on, put all the text and ok button in it just like in a content dialog. and set its canvas.ZIndex="5" property, z index should be more than 0 in order to show it above other content of the application. if you want exactly as in screenshot, set Vertical Alignemnt of grid conrent to center and make the background opacity to 0.6 – Muhammad Touseef Aug 30 '18 at 17:13
  • let me know if this is confusing for you then I will post a answer with some code and better explaination. – Muhammad Touseef Aug 30 '18 at 17:13
  • If possible can you please post the code and add some explanation?I am new to **UWP** and experimenting with **mvvm**. Thanks – sadik Aug 30 '18 at 17:23
  • Also I am trying to show it in a frame and want the popup screen to fully cover the parent layout too(as shown in image). I have tried your instructions and its only visible inside the frame layout.Is that possible? – sadik Aug 30 '18 at 17:37
  • May be you needed this: https://stackoverflow.com/questions/46739337/uwp-show-fullscreen-popup-contentdialog-or-flyout – Muzib Aug 30 '18 at 17:44
  • I need to add some controls in the new dialog. i don't think we can add text and button in rectangle. Is that possible? – sadik Aug 30 '18 at 18:33
  • @sadik yes it is possible the link Muzib provided should work for you, you can just put your controls inside the rectangle which is just a simple Grid :) – Muhammad Touseef Aug 30 '18 at 19:55
  • @touseefbsb I can't create a markup inside rectangle. It doesn't support direct content. The method you suggested using the visibility function worked partially as I was able to show a window as the image but the thing is as I said I am inside the frame and I need the new window to be full screen width that is stretching over the top of the menu(left side) too. I have updated the image attached. – sadik Aug 31 '18 at 04:31
  • @touseefbsb if you can give a sample code that would be greatly helpful as I am new to UWP. – sadik Aug 31 '18 at 04:57

1 Answers1

0

It is actually very simple, did a bit research and found the simplest answer, you can keep doing what you were already doing in the first place and just set the FullSizeDesired property of your ContentDialog to true.

Popup

Or you can try it with popup.

var c = Window.Current.Bounds;
var okButton=new Button{Content="Ok"};
okButton.Click += okButtonClicked; // now where you have this okButtonClicked event you can execute any code you want including, closing the popup.
var g = new Grid
{
    Width = c.Width,
    Height = c.Height,
    Background = new SolidColorBrush(Color.FromArgb(0x20, 0, 0, 0)),
    Children =
    {
        
        new StackPanel
        {
            Width = 400,
            Height = 200,
            Background = new SolidColorBrush(Colors.White),
            Children=
            {
                new TextBlock{Text="Title"},
                new TextBlocl{Text="description"},
                okButton
            }
        }
    }
};
var p = new Popup
{
    HorizontalOffset = 0,
    VerticalOffset = 0,
    Width = c.Width,
    Height = c.Height,
    Child = g
};

p.IsOpen = true; // open when ready

Notice that Child of popup is g which is a grid, you can put your content within this grid or you can use a StackPanel instead of this grid and then put your contents within that StackPanel, whatever you want to do here is your decision, putting elements in popup is exactly like putting elements in a ContentDialog.

Achieving the same with a simple Grid alongside your frame

<Grid>
    <Grid Horizontallignment="Stretch" VerticalAlignment="Stretch" Visibility="Collapsed" x:Name="ContentGrid" canvas.ZIndex="5"><--this grid will act as content dialog, just toggle its visibility to the backend-->
        <--put all your content here along with your ok and cancel buttons-->
    </Grid>
    <Frame/> <--this is the code where you have your frame-->
</Grid>

in above code the frame and your actually content grid will be parallel to each other, and whenever content grid is visible only it will be shown in the app because it has ZIndex greater than 0 and your frame will hide behind it, and whenever its visibility is collapsed it will not be shown and you will be able to see your frame normally.

halfer
  • 19,824
  • 17
  • 99
  • 186
Muhammad Touseef
  • 4,357
  • 4
  • 31
  • 75
  • I have done that but the width wont increase beyond a certain point – sadik Aug 31 '18 at 14:27
  • the screenshot u posted is actually default behaviour of content dialog on xbox – Muhammad Touseef Aug 31 '18 at 14:35
  • I am creating a content dialogue inside a frame and it doesn't become full screen. All the examples I referred said the same and its not working for me.Sorry to bother you again. Added new image of how it is shown in my app – sadik Aug 31 '18 at 14:40
  • So in the code you have given, is that possible to load the content from a file and add click events to it. I have content in the dialog and some buttons associated with that.Can you please give an example of the same. – sadik Aug 31 '18 at 14:44
  • yes you can simply add buttons inside the grid of the popup and attach click events to it, what you are trying to accomplish is pretty unusual, tht is why it is complicated to do and as you are new to uwp it is being difficult for you to implement it exactly – Muhammad Touseef Aug 31 '18 at 15:08
  • if you want it over complete application then you have to set a grid alongside your frame with ZIndex, but in tht case you can only control the visibility of it from the code behind where your frame exists – Muhammad Touseef Aug 31 '18 at 15:09
  • I have updated the popup part of the answer and also I have added a third way of achieving this in the answer, hope that helps. if u still cnt achieve it I suggest you should upload a minimal project to a public github repo and share it with us so I can run it and try to fix it on my machine. – Muhammad Touseef Aug 31 '18 at 15:36