ScrollViewer不会滚动

时间:2012-02-09 14:29:58

标签: windows-phone-7 scrollviewer

我大约一周前开始WP7开发(和一般的编程),我一直在研究一个小应用程序,但是我遇到了让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组合工作得很好。

1 个答案:

答案 0 :(得分:1)

我发现了什么实际上打破了ScrollViewer,它是我设置为在文本更新时触发的过渡动画。我在它上面有一点输入错误,不知何故,当转换工作时,scrollviewer没有。