0
我已经开始大约一周前的WP7开发(和一般编程),我一直在研究一个小应用程序,但是我遇到了让ScrollViewer正常工作的问题。ScrollViewer不滚动
当满足某些条件时,应用程序创建一个新的数据透视表项,并且我试图在其中添加一个可滚动的文本块,每当用户点击屏幕时显示从列表中随机选择的文本字符串,足够长的时间需要垂直滚动。
// A bit cleaned version of my code,
// had to translate stuff a bit for them to make sense
// Sets the PivotItem header depending on user choice
// and creates ScrollViewer and TextBlock
PivotItem newPivotItem = new PivotItem { Header = choice, Name = "newPivot"};
ScrollViewer newScrollviewer = new ScrollViewer();
TextBlock newTextBlock = new TextBlock { Text = "tap the screen", Name = choice};
newScrollviewer.Content = newTextBlock;
newPivotItem.Content = newScrollviewer;
mainPivot.Items.Add(newPivotItem);
在Tap事件中添加了文本,它只是将Text属性替换为新字符串。文本更新很好,并按预期进行,但ScrollViever在更新后停止工作。
newString = list[rand];
PivotItem selectedPivot = mainPivot.SelectedItem as PivotItem;
TextBlock selectedText = selectedPivot.FindName(choice) as TextBlock;
selectedText.Text = newString;
selectedText.Height = selectedText.ActualHeight;
Similiar ScrollViewer - 在xaml中声明的另一个PivotItem中的TextBlock组合工作得很好。