我正在做一个windows通用的应用程序。
我想创建一个弹出式窗口,将充满屏幕,并滚动,如果在弹出式窗口中的内容大于屏幕。
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。
如果我手动设置弹出窗口的高度,它会按预期工作。我的问题是让弹出窗口的高度和宽度填满屏幕。如果不考虑高度,那么高度就是内容的大小,内容会从屏幕上消失,不会滚动。
发布于 2014-09-18 21:21:10
可以在窗口的构造函数中使用System.Windows.SystemParameters.MaximizedPrimaryScreenWidth和System.Windows.SystemParameters.MaximizedPrimaryScreenHeight属性设置宽度和高度,如下所示:
public MainWindow()
{
InitializeComponent();
popup.Width = SystemParameters.MaximizedPrimaryScreenWidth;
popup.Height = SystemParameters.MaximizedPrimaryScreenHeight;
}这是如果你想使用这种方法的话。然而,@pushpraj推荐了满足您需求的最佳方法。
https://stackoverflow.com/questions/25904442
复制相似问题