如何滚动数据透视表的内容
本文关键字:透视 数据 何滚动 滚动 | 更新日期: 2023-09-27 18:25:40
我在页面上有一个这样的枢轴:
<phone:Pivot Name="pivot">
<phone:PivotItem Name="item1">
</phone:PivotItem>
</phone:Pivot>
我想通过编程将一些图像添加到项目中,这样用户就可以上下滚动。当我这样做时,滚动查看器不工作,我的意思是不会向下滚动。
Image image1 = new Image();
image1.Source = ...
Image image2 = new Image();
image2.Source = ...
Image image3 = new Image();
image3.Source = ...
Grid grid2 = new Grid();
grid2.Children.Add(image1);
grid2.Children.Add(image2);
grid2.Children.Add(image3);
ScrollViewer scroll = new ScrollViewer();
scroll.Content = grid2;
item1.Content = scroll;
如何向上和向下滚动以编程方式添加的数据透视项目的内容?无论有没有ScrollViewer
。
好吧,我要做的第一件事是在你的透视中添加一个列表框
<phone:Pivot Name="pivot">
<phone:PivotItem Name="item1">
<ListBox name="ListOfStuff">
</ListBox>
</phone:PivotItem>
</phone:Pivot>
然后,在您的cod中,您不将项目添加到网格中,而是将它们添加到列表框中。
ListOfStuff.Items.Add(ImageWhatever);
应该就是这样了。你的列表框会添加项目并正常滚动。只需确保列表框的高度和宽度设置为屏幕大小或更小。否则您的列表框将无法正常工作。
你甚至可以用这个变得更复杂,做出漂亮的设计。
例如:
StackPanel sp = new StackPane();
Image im1 = new Image();
TextBlock tb = new TextBlock();
//...Put your sizing and editing of objects here...
sp.orientation = System.Windows.Controls.Orientation.Horizontal;
sp.add(im1);
sp.add(tb);
ListOfStuff.Items.Add(sp);
这将导致您有一个旁边有文本块的图像,并且它将是列表中的单个可选项目。