當前位置:
首頁 >
重新想象 Windows 8 Store Apps (10) - 控件之 ScrollViewer 特性: Chaining, Rail, Inertia, Snap, Zoom...
發布時間:2025/6/15
44
豆豆
生活随笔
收集整理的這篇文章主要介紹了
重新想象 Windows 8 Store Apps (10) - 控件之 ScrollViewer 特性: Chaining, Rail, Inertia, Snap, Zoom...
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
原文:重新想象 Windows 8 Store Apps (10) - 控件之 ScrollViewer 特性: Chaining, Rail, Inertia, Snap, Zoom
[源碼下載]
作者:webabcd
介紹
重新想象 Windows 8 Store Apps 之?ScrollViewer
- Chaining -?鎖鏈
- Rail -?軌道
- Inertia -?慣性
- Snap -?對齊
- Zoom - 縮放
示例
1、演示 ScrollViewer 的 Chaining?特性
ScrollViewer/Chaining.xaml
2、演示 ScrollViewer 的 Rail?特性
ScrollViewer/Rail.xaml
3、演示 ScrollViewer 的 Inertia?特性
ScrollViewer/Inertia.xaml
4、演示 ScrollViewer 的 Snap?特性
ScrollViewer/Snap.xaml
ScrollViewer/Snap.xaml.cs
/** Snap: 對齊,在觸摸模式下,如果 ScrollViewer 有多個元素,在滾動結束后會定位到其中某一個具體的元素,這就叫對齊* * HorizontalSnapPointsType - 水平方向上的對齊行為,Windows.UI.Xaml.Controls.SnapPointsType枚舉* SnapPointsType.None - 不需要對齊,默認值* SnapPointsType.Optional - 看情況,如果離某個元素很近則對齊此元素* SnapPointsType.Mandatory - 強制對齊,必須對齊到某一元素* SnapPointsType.OptionalSingle - 僅對 Zoom 對齊有用* SnapPointsType.MandatorySingle - 僅對 Zoom 對齊有用* VerticalSnapPointsType - 垂直方向上的對齊行為* * * HorizontalSnapPointsAlignment - 水平方向上的對齊方式,Windows.UI.Xaml.Controls.Primitives.SnapPointsAlignment枚舉* SnapPointsAlignment.Near - 元素的左側對齊 ScrollViewer 的左側邊界,默認值* SnapPointsAlignment.Center - 元素的中心點對齊 ScrollViewer 的中心點* SnapPointsAlignment.Far - 元素的右側對齊 ScrollViewer 的右側邊界* VerticalSnapPointsAlignment - 垂直方向上的對齊方式* * * BringIntoViewOnFocusChange - ScrollViewer 內的某元素獲得焦點后,是否需要定位到此元素,默認值為 true*/using Windows.UI.Xaml.Controls;namespace XamlDemo.Controls.ScrollViewer {public sealed partial class Snap : Page{public Snap(){this.InitializeComponent();this.Loaded += Snap_Loaded;}void Snap_Loaded(object sender, Windows.UI.Xaml.RoutedEventArgs e){ scrollViewer.HorizontalSnapPointsAlignment = Windows.UI.Xaml.Controls.Primitives.SnapPointsAlignment.Near;scrollViewer.BringIntoViewOnFocusChange = true;}private void ComboBox_SelectionChanged_1(object sender, SelectionChangedEventArgs e){if (scrollViewer != null && comboBox != null){switch (comboBox.SelectedIndex){case 0:scrollViewer.HorizontalSnapPointsType = SnapPointsType.None;break;case 1: scrollViewer.HorizontalSnapPointsType = SnapPointsType.Optional;break;case 3:scrollViewer.HorizontalSnapPointsType = SnapPointsType.Mandatory;break;default:scrollViewer.HorizontalSnapPointsType = SnapPointsType.None;break;}}}private void Button_Click_1(object sender, Windows.UI.Xaml.RoutedEventArgs e){// 當 BringIntoViewOnFocusChange 為 true 時,如果 txtMsg2 獲得焦點,則 ScrollViewer 會自動滾動到 txtMsg2 txtMsg2.Focus(Windows.UI.Xaml.FocusState.Programmatic);}} }
5、演示 ScrollViewer 的 Zoom?特性
ScrollViewer/Zoom.xaml
ScrollViewer/Zoom.xaml.cs
using Windows.UI.Xaml; using Windows.UI.Xaml.Controls;namespace XamlDemo.Controls.ScrollViewer {public sealed partial class Zoom : Page{public Zoom(){this.InitializeComponent();this.Loaded += Zoom_Loaded;}void Zoom_Loaded(object sender, RoutedEventArgs e){/** ZoomSnapPoints - “放大/縮小”的對齊點的集合,默認是空的* * ZoomSnapPointsType - “放大/縮小”的對齊行為* SnapPointsType.None - 不需要對齊,默認值* SnapPointsType.Optional - 看情況,如果離某個對齊點很近則對齊* SnapPointsType.Mandatory - 強制對齊,必須對齊到某一個對齊點* SnapPointsType.OptionalSingle - 同 Optional,但不能跳過對齊點* SnapPointsType.MandatorySingle - 同 Mandatory,但不能跳過對齊點* * IsZoomChainingEnabled - 是否啟用 Zoom 的 Chaining* IsZoomInertiaEnabled - 是否啟用 Zoom 的 Inertia* ZoomFactor - 獲取當前的 Zoom 的倍數* * ZoomToFactor() - Zoom 到指定的倍數*/scrollViewer.ZoomSnapPointsType = SnapPointsType.OptionalSingle;scrollViewer.ZoomSnapPoints.Add(0.5f);scrollViewer.ZoomSnapPoints.Add(0.8f);scrollViewer.ZoomSnapPoints.Add(1.0f);scrollViewer.ZoomSnapPoints.Add(1.5f);scrollViewer.ZoomSnapPoints.Add(2.0f);}private void Button_Click_1(object sender, RoutedEventArgs e){scrollViewer.ZoomToFactor(0.1f);}} }
OK
[源碼下載]
總結
以上是生活随笔為你收集整理的重新想象 Windows 8 Store Apps (10) - 控件之 ScrollViewer 特性: Chaining, Rail, Inertia, Snap, Zoom...的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: -lrt
- 下一篇: 【转】Socket状态变迁图