我已經使用以下代碼創建了一個Popup,但我無法弄清楚如何居中它
我試圖在運行時自動更改邊距,但我無法弄清楚如何去做,但是有沒有人知道如何將彈出窗口居中?
它不具有標準尺寸的原因,我需要全球化,我的程序在XAML中彈出中心
<Grid Background="{StaticResource ApplicationPageBackgroundThemeBrush}" Name="MainGrid">
<Popup x:Uid="LoginPopup" IsOpen="True" Name="LoginPopup">
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="Auto" />
<RowDefinition Height="Auto" />
<RowDefinition Height="Auto"/>
<RowDefinition Height="Auto" />
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="Auto" />
<ColumnDefinition Width="*" />
</Grid.ColumnDefinitions>
<TextBlock Margin="10" Grid.Column="0" Grid.Row="0" Text="App Name" Grid.ColumnSpan="2" Style="{StaticResource HeaderTextStyle}" />
<TextBlock Margin="10" Grid.Column="0" Grid.Row="1" Text="Username" Style="{StaticResource ResourceKey=SubheaderTextStyle}" />
<TextBox Margin="10" Grid.Column="1" Grid.Row="1" Name="InputUsername" />
<TextBlock Margin="10" Grid.Column="0" Grid.Row="2" Text="Password" Style="{StaticResource ResourceKey=SubheaderTextStyle}" />
<PasswordBox Margin="10" Grid.Column="1" Grid.Row="2" Name="InputPassword" />
<StackPanel Margin="10" Grid.Column="1" Grid.Row="3" HorizontalAlignment="Left" Orientation="Horizontal">
<Button Name="Login" x:Uid="LoginPopupLogin" />
<Button Name="Cancel" x:Uid="LoginPopupCancel" />
</StackPanel>
</Grid>
</Popup>
</Grid>
UPDATE
我下面user1603313的答案試過,但它沒有這樣做的伎倆,因爲它說的彈出窗口內的網格大小爲NaN。
我也試過的方法轉移到網格,但它並沒有這樣的伎倆要麼
我說的方法是這樣的與電網正確更新
private void LoginPopup_Loaded_1(object sender, RoutedEventArgs e)
{
LoginPopup.HorizontalOffset = (Window.Current.Bounds.Width - gdChild.ActualWidth)/2;
LoginPopup.VerticalOffset = (Window.Current.Bounds.Height - gdChild.ActualHeight)/2;
}
你會被認爲彈出按鈕。 http://msdn.microsoft.com/en-us/library/windows/apps/hh465354.aspx –
@SinanErgin當我閱讀時,Flyouts僅適用於HTML – The87Boy
啊,這是真的。彈出不可以使用xaml + c#/ vb。良好的工作;) –