首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >带有滚动视图的全屏弹出窗口

问带有滚动视图的全屏弹出窗口
EN

Stack Overflow用户
提问于 2014-09-18 12:59:22
回答 1查看 784关注 0票数 1

我正在做一个windows通用的应用程序。

我想创建一个弹出式窗口,将充满屏幕,并滚动,如果在弹出式窗口中的内容大于屏幕。

代码语言:javascript
复制
Popup testPopup = new Popup();

StackPanel testStackPanel = new StackPanel();

ScrollViewer testScrollViewer = new ScrollViewer();
testScrollViewer.Background = new SolidColorBrush(Windows.UI.Colors.Green);
testScrollViewer.Height = new GridLength(1, GridUnitType.Star).Value; //this sets the height to one pixel     instead of filling the screen.

Button testPopupButton = new Button();
testPopupButton.Content = "click";
testPopupButton.Click += delegate(object sender, RoutedEventArgs e)
{
    testPopup.IsOpen = true;
};

Button closePopupButton = new Button();
closePopupButton.Content = "close";
closePopupButton.Click += delegate(object sender, RoutedEventArgs e)
{
    testPopup.IsOpen = false;
};

for (int i = 0; i < 20; i++)
{
    Button b = new Button();
    b.Content = i;

    testStackPanel.Children.Add(b);
}

testStackPanel.Children.Add(closePopupButton);

testPopup.Child = testScrollViewer;
testScrollViewer.Content = testStackPanel;
ContentRoot.Children.Add(testPopupButton);
ContentRoot.Children.Add(testPopup);

我创建了一个弹出式窗口,它的子级设置为scrollViewer,并且scrollViewers内容是一个比屏幕高度高的stackPanel。

如果我手动设置弹出窗口的高度,它会按预期工作。我的问题是让弹出窗口的高度和宽度填满屏幕。如果不考虑高度,那么高度就是内容的大小,内容会从屏幕上消失,不会滚动。

EN

回答 1

Stack Overflow用户

发布于 2014-09-18 21:21:10

可以在窗口的构造函数中使用System.Windows.SystemParameters.MaximizedPrimaryScreenWidth和System.Windows.SystemParameters.MaximizedPrimaryScreenHeight属性设置宽度和高度,如下所示:

代码语言:javascript
复制
public MainWindow()
{
    InitializeComponent();
    popup.Width = SystemParameters.MaximizedPrimaryScreenWidth;
    popup.Height = SystemParameters.MaximizedPrimaryScreenHeight;
}

这是如果你想使用这种方法的话。然而,@pushpraj推荐了满足您需求的最佳方法。

票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/25904442

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档