2 回答

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;
}
此致。

TA貢獻2019條經驗 獲得超9個贊
遺憾的是彈出窗口不支持對齊方式,您必須使用偏移值
注意:不要忘記您可以使用偏移綁定,從而通過一些轉換器魔法獲得您想要的行為。
<Popup?HorizontalOffset="20"? ???????VerticalOffset="10"> ????<!--Content--> ????</Popup>
- 2 回答
- 0 關注
- 171 瀏覽
添加回答
舉報