亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

如何讓Popup出現在特定的角落

如何讓Popup出現在特定的角落

C#
明月笑刀無情 2023-08-13 16:15:53
我希望我的Popup始終出現在特定的角落(例如右下角),無論我的View.我嘗試使用HorizontalAlignment但VerticalAlignment它并沒有真正起作用。這是我的代碼:<Grid x:Name="Output" HorizontalAlignment="Right" VerticalAlignment="Bottom" Grid.Row="1">    <Popup x:Name="StandardPopup">        <Border BorderBrush="{StaticResource ApplicationForegroundThemeBrush}"             Background="{StaticResource ApplicationPageBackgroundThemeBrush}"            BorderThickness="2" Width="500" Height="500">            <StackPanel HorizontalAlignment="Center" VerticalAlignment="Center">                <WebView x:Name="WebView1" Source="https://www.bing.com/" Width="490" Height="490" HorizontalAlignment="Center"/>            </StackPanel>        </Border>    </Popup></Grid>
查看完整描述

2 回答

?
qq_遁去的一_1

TA貢獻1725條經驗 獲得超8個贊

您可以創建一個 UserControl 來幫助您實現這一目標。


創建一個名為 TestPopup 的新 UserControl


<UserControl

    ...

    >


    <Grid>

        <Grid HorizontalAlignment="Right" VerticalAlignment="Bottom">

            <Border BorderBrush="{StaticResource ApplicationForegroundThemeBrush}" 

            Background="{StaticResource ApplicationPageBackgroundThemeBrush}"

            BorderThickness="2" Width="500" Height="500">

                <StackPanel HorizontalAlignment="Center" VerticalAlignment="Center">

                    <WebView x:Name="WebView1" Source="https://www.bing.com/" Width="490" Height="490" HorizontalAlignment="Center"/>

                </StackPanel>

            </Border>

        </Grid>

    </Grid>


</UserControl>

后臺代碼:


public sealed partial class TestPopup : UserControl

{

    private Popup _popup = null;

    public TestPopup()

    {

        this.InitializeComponent();

        // If you need to top placement, please comment out the Width/Height statement below

        this.Width = Window.Current.Bounds.Width;

        this.Height = Window.Current.Bounds.Height;


        //Assign the current control to the Child property of the popup. The Child property is what the popup needs to display.

        _popup = new Popup();

        _popup.Child = this;

    }

    public void ShowPopup()

    {

        _popup.IsOpen = true;

    }

    public void HidePopup()

    {

        _popup.IsOpen = false;

    }

}

在需要時使用 C# 代碼引用


public sealed partial class MainPage : Page

{

    private TestPopup _popup = new TestPopup();

    public MainPage()

    {

        this.InitializeComponent();

        _popup.ShowPopup();

    }

}

保證任意寬度下都在右下角,可以監聽頁面的SizeChanged事件。


private void Page_SizeChanged(object sender, SizeChangedEventArgs e)

{

    _popup.Width = Window.Current.Bounds.Width;

    _popup.Height = Window.Current.Bounds.Height;

    // If you need to use the Width/Height of the page

    // _popup.Width = e.NewSize.Width;

    // _popup.Height = e.NewSize.Height;

}

此致。


查看完整回答
反對 回復 2023-08-13
?
慕少森

TA貢獻2019條經驗 獲得超9個贊

遺憾的是彈出窗口不支持對齊方式,您必須使用偏移值

注意:不要忘記您可以使用偏移綁定,從而通過一些轉換器魔法獲得您想要的行為。

<Popup?HorizontalOffset="20"?
???????VerticalOffset="10">
????<!--Content-->
????</Popup>


查看完整回答
反對 回復 2023-08-13
  • 2 回答
  • 0 關注
  • 171 瀏覽

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號