2 回答
TA贡献1725条经验 获得超7个赞
您可以创建一个 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 关注
- 126 浏览
添加回答
举报