重新想象 Windows 8 Store Apps (9) - 控件之 ScrollViewer 基础
生活随笔
收集整理的這篇文章主要介紹了
重新想象 Windows 8 Store Apps (9) - 控件之 ScrollViewer 基础
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
原文:重新想象 Windows 8 Store Apps (9) - 控件之 ScrollViewer 基礎
[源碼下載]
作者:webabcd
介紹
重新想象 Windows 8 Store Apps 之?ScrollViewer
- 演示 ScrollViewer 的基本應用
- 演示 ScrollBar 的基本應用
- 演示 ScrollContentPresenter 的基本應用
示例
1、ScrollViewer 的基本應用
ScrollViewer/Demo.xaml
ScrollViewer/Demo.xaml.cs
/** ScrollViewer - 滾動視圖控件* * 本例用于演示 ScrollViewer 的基本用法*/using Windows.UI.Xaml; using Windows.UI.Xaml.Controls;namespace XamlDemo.Controls.ScrollViewer {public sealed partial class Demo : Page{public Demo(){this.InitializeComponent();}private void scrollViewer_ViewChanged_1(object sender, ScrollViewerViewChangedEventArgs e){lblMsg.Text = "";/** ScrollViewer - 滾動視圖控件* ComputedHorizontalScrollBarVisibility - 當前水平滾動條的可見性,比如當 HorizontalScrollBarVisibility 設置為 Auton 時,可以通過 ComputedHorizontalScrollBarVisibility 來判斷當前水平滾動條是否可見* ComputedVerticalScrollBarVisibility - 當前垂直滾動條的可見性* ExtentWidth - ScrollViewer 內的內容的寬* ExtentHeight - ScrollViewer 內的內容的高* ViewportWidth - 可視區的寬* ViewportHeight - 可視區的高* HorizontalOffset - 滾動內容的水平方向的偏移量* VerticalOffset - 滾動內容的垂直方向的偏移量* ScrollableWidth - 可滾動區域的水平方向的大小* ScrollableHeight - 可滾動區域的垂直方向的大小* * ScrollToHorizontalOffset() - 滾動到指定的水平偏移位置* ScrollToVerticalOffset() - 滾動到指定的垂直偏移位置*/lblMsg.Text += "ComputedHorizontalScrollBarVisibility: " + scrollViewer.ComputedHorizontalScrollBarVisibility;lblMsg.Text += "\r\n";lblMsg.Text += "ComputedVerticalScrollBarVisibility: " + scrollViewer.ComputedVerticalScrollBarVisibility;lblMsg.Text += "\r\n";lblMsg.Text += "ExtentWidth: " + scrollViewer.ExtentWidth;lblMsg.Text += "\r\n";lblMsg.Text += "ExtentHeight: " + scrollViewer.ExtentHeight;lblMsg.Text += "\r\n";lblMsg.Text += "ViewportWidth: " + scrollViewer.ViewportWidth;lblMsg.Text += "\r\n";lblMsg.Text += "ViewportHeight: " + scrollViewer.ViewportHeight;lblMsg.Text += "\r\n";lblMsg.Text += "HorizontalOffset: " + scrollViewer.HorizontalOffset;lblMsg.Text += "\r\n";lblMsg.Text += "VerticalOffset: " + scrollViewer.VerticalOffset;lblMsg.Text += "\r\n";lblMsg.Text += "ScrollableWidth: " + scrollViewer.ScrollableWidth;lblMsg.Text += "\r\n";lblMsg.Text += "ScrollableHeight: " + scrollViewer.ScrollableHeight;lblMsg.Text += "\r\n";}private void Button_Click_1(object sender, RoutedEventArgs e){scrollViewer.ScrollToHorizontalOffset(scrollViewer.ScrollableWidth / 2);scrollViewer.ScrollToVerticalOffset(scrollViewer.ScrollableHeight / 2);}} }
2、ScrollBar 的基本應用
ScrollViewer/ScrollBarDemo.xaml
ScrollViewer/ScrollBarDemo.xaml.cs
/** ScrollBar - 滾動條控件* * 本例通過訪問 ScrollViewer 內的名為 VerticalScrollBar 的 ScrollBar 控件,來簡要說明 ScrollBar 控件*/using Windows.UI.Xaml; using Windows.UI.Xaml.Controls; using Windows.UI.Xaml.Controls.Primitives; using XamlDemo.Common;namespace XamlDemo.Controls.ScrollViewer {public sealed partial class ScrollBarDemo : Page{public ScrollBarDemo(){this.InitializeComponent();this.Loaded += ScrollBarDemo_Loaded;}void ScrollBarDemo_Loaded(object sender, RoutedEventArgs e){// 找到 ScrollViewer 內的名為 VerticalScrollBar 的 ScrollBar 控件,即 ScrollViewer 內的垂直滾動條var scrollBar = Helper.GetVisualChild<ScrollBar>(scrollViewer, "VerticalScrollBar");// ValueChanged - 當滾動條的值發生改變是所觸發的事件scrollBar.ValueChanged += scrollBar_ValueChanged;}void scrollBar_ValueChanged(object sender, RangeBaseValueChangedEventArgs e){// 顯示垂直滾動條的當前值lblMsg.Text = e.NewValue.ToString();}} }
3、ScrollContentPresenter 的基本應用
ScrollViewer/ScrollContentPresenterDemo.xaml
ScrollViewer/ScrollContentPresenterDemo.xaml.cs
/** ScrollContentPresenter - ScrollViewer 的內容呈現器(類似的有 ContentPresenter, ItemsPresenter)* * ScrollContentPresenter 用來呈現 ScrollViewer 的 Content*/using Windows.UI.Xaml; using Windows.UI.Xaml.Controls; using XamlDemo.Common;namespace XamlDemo.Controls.ScrollViewer {public sealed partial class ScrollContentPresenterDemo : Page{public ScrollContentPresenterDemo(){this.InitializeComponent();this.Loaded += ScrollContentPresenterDemo_Loaded;}void ScrollContentPresenterDemo_Loaded(object sender, RoutedEventArgs e){// 找到 ScrollViewer 內的名為 ScrollContentPresenter 的 ScrollContentPresenter 控件var scrollContentPresenter = Helper.GetVisualChild<ScrollContentPresenter>(scrollViewer, "ScrollContentPresenter");scrollContentPresenter.Margin = new Thickness(100);}} }
OK
[源碼下載]
總結
以上是生活随笔為你收集整理的重新想象 Windows 8 Store Apps (9) - 控件之 ScrollViewer 基础的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: loadrunner脚本中参数有中文时报
- 下一篇: 宝宝巴士app怎么下载电脑(宝宝发出这六