弹出使用整个屏幕的宽度和高度 - Windows应用程序

问题描述:

我想创建一个自定义对话框有很多TextBlocks,文本框和按钮。经过一段时间的研究后,我在我的Grid中实现了一个'Popup',它有一些我的表单UI。弹出使用整个屏幕的宽度和高度 - Windows应用程序

如何在页面中心弹出对话框。我曾尝试使用horizo​​ntalOffset和VerticalOffset,但弹出窗口仍然填充在我用来填充弹出窗口的按钮下方。

我也有两个,如果你能指导我在正确的方向问题:

  • 这是填充在Windows应用程序的自定义对话框的(对平板电脑)的正确方法?
  • 如何从其他页面重新使用弹出窗口?

在此先感谢 饶

MainPage.xaml中

<Button 
       x:Name="bFour" 
       Content="Popup with buttons and text" 
       Height="75" FontSize="32" 
       Click="bFour_Click"/> 


     <Popup x:Name="Popup1" 
       IsOpen="False" 
       LayoutUpdated="Popup1_LayoutUpdated" 
       HorizontalAlignment="Center" 
       VerticalAlignment="Top"> 
      <StackPanel Background="Blue" 
         Width="5000" 
         Height="5000"> 
       <TextBlock Text="One" FontSize="54"/> 
       <TextBlock Text="Two" FontSize="54"/> 
       <Button x:Name="bClosepopup" Content="Close Popup" Click="bClosepopup_Click"/>   
      </StackPanel> 

     </Popup> 

MainPage.xaml.cs中

private void bFour_Click(object sender, RoutedEventArgs e) 
    { 
     //Popup1.HorizontalOffset = r.Next(100, 100); 
     //Popup1.HorizontalOffset = (Window.Current.Bounds.Width - gdMain.ActualWidth)/2; 
     //Popup1.VerticalOffset = (Window.Current.Bounds.Height - gdMain.ActualHeight)/2; 
     //Popup1.Height = ActualHeight; 
     //Popup1.Width = ActualWidth; 
     Popup1.IsOpen = true; 
    } 

    private void Popup1_LayoutUpdated(object sender, object e) 
    { 
     if (gdMain.ActualWidth == 0 && gdMain.ActualHeight == 0) 
     { 
      return; 
     } 

     double ActualHorizontalOffset = this.Popup1.HorizontalOffset; 
     double ActualVerticalOffset = this.Popup1.VerticalOffset; 

     double NewHorizontalOffset = (Window.Current.Bounds.Width - gdMain.ActualWidth)/2; 
     double NewVerticalOffset = (Window.Current.Bounds.Height - gdMain.ActualHeight)/2; 

     if (ActualHorizontalOffset != NewHorizontalOffset || ActualVerticalOffset != NewVerticalOffset) 
     { 
      this.Popup1.HorizontalOffset = NewHorizontalOffset; 
      this.Popup1.VerticalOffset = NewVerticalOffset; 
     } 
    } 

我认为你缺少2个属性:

尝试用这些,看看效果更好。

编辑1:

不幸的是弹出窗口中的Windows应用程序不具有相同的属性,正常WPF应用程序。这里是documentation。弹出窗口似乎并不是实现你想要做的事情的正确方法。


为了您2个其他问题:

+0

嗨Kotix,你可以给我可以按照 – BRDroid

+0

由于您的问题包含多个实际问题的任何例子,我建议你尝试一些东西,问你遇到的问题更具体的问题。对于MVVM项目的例子,我会用图书馆主开发人员制作的一个很棒的视频教程来编辑我的答案。 – KOTIX

+0

您能否提出关于展示位置目标和展示位置使用情况的任何示例。 – BRDroid