我想創建一個自定義對話框有很多TextBlocks,文本框和按鈕。經過一段時間的研究後,我在我的Grid中實現了一個'Popup',它有一些我的表單UI。彈出使用整個屏幕的寬度和高度 - Windows應用程序
如何在頁面中心彈出對話框。我曾嘗試使用horizontalOffset和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;
}
}
嗨Kotix,你可以給我可以按照 – BRDroid
由於您的問題包含多個實際問題的任何例子,我建議你嘗試一些東西,問你遇到的問題更具體的問題。對於MVVM項目的例子,我會用圖書館主開發人員製作的一個很棒的視頻教程來編輯我的答案。 – KOTIX
您能否提出關於展示位置目標和展示位置使用情況的任何示例。 – BRDroid