UWP:“内容”对话框的宽度保持不变

时间:2018-08-30 16:06:36

标签: xaml uwp xbox

我尝试设置宽度以及最小高度和最小宽度,但是仍然无法将对话框更改为全屏显示。也尝试过window.bounds,但是对话框不会扩展到固定宽度之外。

    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

1 个答案:

答案 0 :(得分:0)

这实际上非常简单,做了一些研究并找到了最简单的答案,您可以首先继续做您已经在做的事情,而只需设置您的 FullSizeDesired 属性ContentDialog 到 true

弹出

或者您可以尝试弹出窗口。

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
  

请注意弹出子窗口为 g ,这是一个网格,您可以将您的内容放在此网格中,也可以使用 StackPanel 代替此网格,然后放入在StackPanel中的内容之后,您要做的就是您的决定,将元素放入弹出窗口就像将元素放入ContentDialog中一样。

通过框架旁边的简单网格实现相同效果

<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 t the backend-->
        <--put all your content here along with ur ok and cancel buttons-->
    </Grid>
    <Frame/> <--this is the code where u hve ur frame-->
</Grid>

在上面的代码中,框架和您实际的内容网格将彼此平行,并且只要内容网格可见,它将在应用程序中显示bcz,它的 ZIndex 大于0且ur框将隐藏在它的后面,并且只要它的能见度被折叠就不会显示,并且您将能够正常看到您的框。