重新想象 Windows 8 Store Apps (9) - 控件之 ScrollViewer 基础
生活随笔
收集整理的這篇文章主要介紹了
重新想象 Windows 8 Store Apps (9) - 控件之 ScrollViewer 基础
小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.
原文:重新想象 Windows 8 Store Apps (9) - 控件之 ScrollViewer 基礎(chǔ)
[源碼下載]
作者:webabcd
介紹
重新想象 Windows 8 Store Apps 之?ScrollViewer
- 演示 ScrollViewer 的基本應(yīng)用
- 演示 ScrollBar 的基本應(yīng)用
- 演示 ScrollContentPresenter 的基本應(yīng)用
示例
1、ScrollViewer 的基本應(yīng)用
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 - 當(dāng)前水平滾動條的可見性,比如當(dāng) HorizontalScrollBarVisibility 設(shè)置為 Auton 時,可以通過 ComputedHorizontalScrollBarVisibility 來判斷當(dāng)前水平滾動條是否可見* ComputedVerticalScrollBarVisibility - 當(dāng)前垂直滾動條的可見性* ExtentWidth - ScrollViewer 內(nèi)的內(nèi)容的寬* ExtentHeight - ScrollViewer 內(nèi)的內(nèi)容的高* ViewportWidth - 可視區(qū)的寬* ViewportHeight - 可視區(qū)的高* HorizontalOffset - 滾動內(nèi)容的水平方向的偏移量* VerticalOffset - 滾動內(nèi)容的垂直方向的偏移量* ScrollableWidth - 可滾動區(qū)域的水平方向的大小* ScrollableHeight - 可滾動區(qū)域的垂直方向的大小* * 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 的基本應(yīng)用
ScrollViewer/ScrollBarDemo.xaml
ScrollViewer/ScrollBarDemo.xaml.cs
/** ScrollBar - 滾動條控件* * 本例通過訪問 ScrollViewer 內(nèi)的名為 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 內(nèi)的名為 VerticalScrollBar 的 ScrollBar 控件,即 ScrollViewer 內(nèi)的垂直滾動條var scrollBar = Helper.GetVisualChild<ScrollBar>(scrollViewer, "VerticalScrollBar");// ValueChanged - 當(dāng)滾動條的值發(fā)生改變是所觸發(fā)的事件scrollBar.ValueChanged += scrollBar_ValueChanged;}void scrollBar_ValueChanged(object sender, RangeBaseValueChangedEventArgs e){// 顯示垂直滾動條的當(dāng)前值lblMsg.Text = e.NewValue.ToString();}} }
3、ScrollContentPresenter 的基本應(yīng)用
ScrollViewer/ScrollContentPresenterDemo.xaml
ScrollViewer/ScrollContentPresenterDemo.xaml.cs
/** ScrollContentPresenter - ScrollViewer 的內(nèi)容呈現(xiàn)器(類似的有 ContentPresenter, ItemsPresenter)* * ScrollContentPresenter 用來呈現(xiàn) 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 內(nèi)的名為 ScrollContentPresenter 的 ScrollContentPresenter 控件var scrollContentPresenter = Helper.GetVisualChild<ScrollContentPresenter>(scrollViewer, "ScrollContentPresenter");scrollContentPresenter.Margin = new Thickness(100);}} }
OK
[源碼下載]
總結(jié)
以上是生活随笔為你收集整理的重新想象 Windows 8 Store Apps (9) - 控件之 ScrollViewer 基础的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: loadrunner脚本中参数有中文时报
- 下一篇: 宝宝巴士app怎么下载电脑(宝宝发出这六