如何在窗口商店应用程序中居中弹出

本文关键字:中居 应用程序 窗口 | 更新日期: 2023-09-27 18:28:04

我有一个带有自定义弹出窗口(UserHelperButton)的用户控件。我已经手动设置了垂直和水平偏移,以在正确的位置显示弹出窗口。现在我需要更新它的位置到中心。我不能把它放在x轴和垂直轴的中心。

在根窗口上,我在的不同位置添加了UserHelperButton

<Grid Margin="0,0,0,25">
<Grid.ColumnDefinitions>
    <ColumnDefinition Width="120" />
    <ColumnDefinition Width="50" />
    <ColumnDefinition Width="50" />
    <ColumnDefinition Width="120" />
    <ColumnDefinition Width="50" />
    <ColumnDefinition Width="*" />
    <ColumnDefinition Width="120" />
    <ColumnDefinition Width="50" />
</Grid.ColumnDefinitions>
<UserControls:UserLabel Text="Varnost v dvoje" Grid.Column="0" />
<UserControls:UserCheckBox x:Name="cbxDouble" Grid.Column="1" cbxClick="cbxDouble_cbxClick" />
<UserControls:UserHelperButton Grid.Column="2" HelperText="V primeru, da se zavarujeta dve osebi, obe zavarovani osebi pridobita nižjo premijo za sklenjena zavarovanja." />
<UserControls:UserLabel x:Name="lblRefNum" Text="Referenčna številka" Grid.Column="3" />
<UserControls:UserCheckBox x:Name="cbxRefNum" Grid.Column="4" cbxClick="cbxRefNum_cbxClick" />
<UserControls:UserTextBox x:Name="txbRefNum" Grid.Column="5" ValidationMessage="Vnesite referenčno številko!" />
<UserControls:UserLabel Text="Zaposlen na Pošta Slovenija" Grid.Column="6" />
<UserControls:UserCheckBox x:Name="cbxPS" Grid.Column="7" cbxClick="cbxPS_cbxClick" />

<Grid Margin="0,25,0,0">
                        <Grid.ColumnDefinitions>
                            <ColumnDefinition Width="500" />
                            <ColumnDefinition Width="*" />
                            <ColumnDefinition Width="50" />
                        </Grid.ColumnDefinitions>
                        <UserControls:UserLabel Grid.Column="0" x:Name="lblInsurance" Text="Priporočena varnost do 65. leta" LabelMode="Heading" ValidationMessage="Vsota zavarovanj je premajhna!"  />
                        <UserControls:UserHelperButton x:Name="helper2" Grid.Column="2" />
                    </Grid>

userControl xaml:

<Grid x:Name="grid" Margin="0" MaxHeight="50" Canvas.ZIndex="4" VerticalAlignment="Center">
<Button x:Name="btnHelper" AutomationProperties.Name="" Style="{StaticResource HelpAppBarButtonStyle}" HorizontalAlignment="Left" VerticalAlignment="Center" Height="70" Click="btnHelper_Click" />
    <Popup x:Name="popHelper" IsLightDismissEnabled="True" VerticalOffset="-150" HorizontalOffset="-50">
        <Border BorderThickness="25" CornerRadius="25" BorderBrush="Gray" Background="Gray">
            <Grid Background="Gray" Width="400" Height="300">
                <Grid.RowDefinitions>
                    <RowDefinition Height="60" />
                    <RowDefinition Height="*" />
                </Grid.RowDefinitions>
                <local:UserLabel Text="Pomoč" LabelMode="Heading" VerticalAlignment="Top" />
                <Button x:Name="btnClose" AutomationProperties.Name="" Grid.Row="0" Style="{StaticResource NoAppBarButtonStyle}" HorizontalAlignment="Right" VerticalAlignment="Top" Padding="12,0,0,0" Height="100" Click="btnClose_Click" RenderTransformOrigin="0.5,0.5" >
                    <Button.RenderTransform>
                        <CompositeTransform TranslateY="-15"/>
                    </Button.RenderTransform>
                </Button>
                    <WebView x:Name="webviewControl" Grid.Row="1" Margin="0,20,0,0" Height="200" Width="400" />
            </Grid>
        </Border>
    </Popup>

加载事件我用帮助文本填充弹出窗口

        private void UserControl_Loaded(object sender, RoutedEventArgs e)
    {
        string html = "<html><body style='"font-family: 'Segoe UI'; background-color: gray; color: white; margin: 0;'">" + g_text + "</body></html>";
        var fragment = HtmlFormatHelper.GetStaticFragment(HtmlFormatHelper.CreateHtmlFormat(html));
        webviewControl.NavigateToString(fragment);
    }

那么我该怎么做呢?

Thx

Poki

如何在窗口商店应用程序中居中弹出

我这样做:

    private void popup_Loaded(object sender, RoutedEventArgs e)
    {
        popup.HorizontalOffset = (Window.Current.Bounds.Width - popupGrid.Width) / 2;
        popup.VerticalOffset = (Window.Current.Bounds.Height - popupGrid.Height) / 2;
    }