是否有任何方法使ScrollVIEwer自动滚动,使聚焦的控件始终可见.没有,有什么办法可以使这项工作,不听每个控件上的GotFocus事件,然后滚动ScrollVIEwer使控件可见?
目前我正在使用Silverlight 2.
解决方法 我使用Silverlight 3测试了这个.我不知道SL2.这是我的XAML:
<ScrollVIEwer Height="200" WIDth="200" KeyUp="ScrollVIEwer_KeyUp"> <StackPanel> <button Content="1" Height="20" /> <button Content="2" Height="20" /> <button Content="3" Height="20" /> <button Content="4" Height="20" /> <button Content="5" Height="20" /> <button Content="6" Height="20" /> <button Content="7" Height="20" /> <button Content="8" Height="20" /> <button Content="9" Height="20" /> <button Content="10" Height="20" /> <button Content="11" Height="20" /> <button Content="12" Height="20" /> <button Content="13" Height="20" /> <button Content="14" Height="20" /> <button Content="15" Height="20" /> <button Content="16" Height="20" /> <button Content="17" Height="20" /> <button Content="18" Height="20" /> <button Content="19" Height="20" /> <button Content="20" Height="20" /> </StackPanel></ScrollVIEwer>
这是代码隐藏:
private voID ScrollVIEwer_KeyUp(object sender,KeyEventArgs e){ ScrollVIEwer scrollVIEwer = sender as ScrollVIEwer; FrameworkElement focusedElement = FocusManager.GetFocusedElement() as FrameworkElement; Generaltransform focusedVisualtransform = focusedElement.transformToVisual(scrollVIEwer); Rect rectangle = focusedVisualtransform.transformBounds(new Rect(new Point(focusedElement.margin.left,focusedElement.margin.top),focusedElement.RenderSize)); double newOffset = scrollVIEwer.VerticalOffset + (rectangle.Bottom - scrollVIEwer.VIEwportHeight); scrollVIEwer.ScrollToVerticalOffset(newOffset);}
我做的是点击按钮#1和标签,直到我到达按钮#20.它为我工作尝试一下,让我知道它对你有用.
总结以上是内存溢出为你收集整理的如何使Silverlight ScrollViewer滚动显示一个有焦点的子控件?全部内容,希望文章能够帮你解决如何使Silverlight ScrollViewer滚动显示一个有焦点的子控件?所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)