大佬教程收集整理的这篇文章主要介绍了如何使Silverlight ScrollViewer滚动显示一个有焦点的子控件?,大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。
是否有任何方法使ScrollViewer自动滚动,使聚焦的控件始终可见.没有,有什么办法可以使这项工作,不听每个控件上的GotFocus事件,然后滚动ScrollViewer使控件可见?
目前我正在使用Silverlight 2.
这是我的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滚动显示一个有焦点的子控件?所遇到的程序开发问题。
如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。
本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。