我正在开发一个UWP应用程序,并实现了一个弹出窗口。弹出窗口应该在Portrait
以及Landscape
模式下工作。我已经为横向模式实现了弹出窗口,但在portrait
模式下,它将出现在屏幕顶部。这是代码
<Popup x:Name="InValidEntry" Opened="InValidEntry_Opened" x:FieldModifier="Public" IsOpen="{x:Bind ViewModel.FuelPlanInfo.IsInvalidPopupOpened, Mode=TwoWay}" IsLightDismissEnabled="False"
HorizontalAlignment="Center" VerticalAlignment="Center" Margin="0,0,0,0" RenderTransformOrigin="0.5,0.5" Height="396" Width="1047" >
<Canvas x:Name="InValidEntryCanvas" Height="396" Width="1047" Background="{ThemeResource InvalidPopUpBrush}">
<StackPanel x:Name="InValidEntrySP" Width="770" Height="144" Orientation="Vertical" Canvas.Left="46" Canvas.Top="29" >
<Grid x:Name="ParentGrid">
<Grid.RowDefinitions>
<RowDefinition Height="*" />
<RowDefinition Height="*"/>
</Grid.RowDefinitions>
<TextBlock x:Name="InvalidEntryMessage" Text="Invalid Entry" FontWeight="Bold" Foreground="{ThemeResource TextColorBrush}" FontFamily="Helvetica" FontSize="40" Grid.Row="0" />
<TextBlock x:Name="InvalidEntryName" Text="{Binding FuelPlanInfo.InvalidPopupText}" FontFamily="Helvetica" FontSize="40" Grid.Row="1" Foreground="{ThemeResource TextColorBrush}" Margin="0,20,0,0" />
</Grid>
</StackPanel>
<StackPanel x:Name="OKButtonSP" Canvas.Left="724" Canvas.Top="274">
<Button x:Name="OKButton" Content="OK" Width="270" Height="72" FontSize="40" Style="{ThemeResource EFFBaseButtonStyle}" FontFamily="Helvetica" FontWeight="Bold" Foreground="#FFFFFF" Background="#0078D7" Tapped="Button_Tapped" />
</StackPanel>
</Canvas>
</Popup>
我正在管理这样的
Opened="InValidEntry_Opened"
private void InValidEntry_Opened(object sender, object e)
{
ApplicationViewOrientation orientation = ApplicationView.GetForCurrentView().Orientation;
//if (orientation == ApplicationViewOrientation.Landscape)
//{
InValidEntry.HorizontalOffset = 0;
InValidEntry.VerticalOffset = 450 + (FlightPlanScrollViewer.VerticalOffset * 2);
//}
//else
//{
//InValidEntry.VerticalOffset = 0;
//InValidEntry.HorizontalOffset=400+ (FlightPlanScrollViewer.VerticalOffset * 2);
//}
}
我遇到了问题,因为Potrait
模式下的展示位置不合适,但在landscape
模式下效果很好。
要求是在屏幕的center
打开弹出窗口。