背水一战 Windows 10 (47) - 控件(ScrollViewer 特性): Chaining, Rail, Inertia, Snap, Zoom
作者:webabcd
介绍
背水一战 Windows 10 之 控件(ScrollViewer 特性)
- Chaining - 锁链
- Rail - 轨道
- Inertia - 惯性
- Snap - 对齐
- Zoom - 缩放
示例
1、演示 ScrollViewer 的 Chaining 特性
Controls/ScrollViewerDemo/Chaining.xaml
<Page
x:Class="Windows10.Controls.ScrollViewerDemo.Chaining"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="using:Windows10.Controls.ScrollViewerDemo"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
mc:Ignorable="d"> <Grid Background="Transparent">
<StackPanel Margin="10 0 10 10"> <ScrollViewer HorizontalScrollMode="Enabled" VerticalScrollMode="Enabled">
<StackPanel> <CheckBox Name="chkIsHorizontalScrollChainingEnabled" Content="IsHorizontalScrollChainingEnabled" IsChecked="True" Margin="5" />
<CheckBox Name="chkIsVerticalScrollChainingEnabled" Content="IsVerticalScrollChainingEnabled" IsChecked="True" Margin="5" /> <TextBlock Text="我是参照物" Margin="5" /> <!--
Chaining: 锁链,在触摸模式下,滚动本 ScrollViewer 如果超出了边界,则滚动其父 ScrollViewer
本例的测试方法:在触摸模式下,滚动 ScrollViewer 内的内容直至超出边界,超出边界后不要停下来继续滚动,通过“我是参照物”观察父 ScrollViewer 是否也被滚动 IsHorizontalScrollChainingEnabled - 是否启用水平方向上的 Chaining,默认值为 true
IsVerticalScrollChainingEnabled - 是否启用垂直方向上的 Chaining,默认值为 true
--> <ScrollViewer Name="scrollViewer" Width="400" Height="400" Margin="5" HorizontalAlignment="Left"
HorizontalScrollMode="Enabled" VerticalScrollMode="Enabled"
HorizontalScrollBarVisibility="Visible" VerticalScrollBarVisibility="Visible"
IsHorizontalScrollChainingEnabled="{Binding IsChecked, ElementName=chkIsHorizontalScrollChainingEnabled}"
IsVerticalScrollChainingEnabled="{Binding IsChecked, ElementName=chkIsVerticalScrollChainingEnabled}">
<Image Source="/Assets/StoreLogo.png" Width="1000" />
</ScrollViewer> </StackPanel>
</ScrollViewer> </StackPanel>
</Grid>
</Page>
2、演示 ScrollViewer 的 Rail 特性
Controls/ScrollViewerDemo/Rail.xaml
<Page
x:Class="Windows10.Controls.ScrollViewerDemo.Rail"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="using:Windows10.Controls.ScrollViewerDemo"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
mc:Ignorable="d"> <Grid Background="Transparent">
<StackPanel Margin="10 0 10 10"> <CheckBox Name="chkIsHorizontalRailEnabled" Content="IsHorizontalRailEnabled" IsChecked="True" Margin="5" />
<CheckBox Name="chkIsVerticalRailEnabled" Content="IsVerticalRailEnabled" IsChecked="True" Margin="5" /> <!--
Rail: 轨道,在触摸模式下,假设沿水平方向滚动,则由于轨道的作用,在松手前只能延水平方向滚动(即使手指有垂直方向的滚动也无用) IsHorizontalRailEnabled - 是否启用水平方向上的轨道,默认值为 true
IsVerticalRailEnabled - 是否启用垂直方向上的轨道,默认值为 true
--> <ScrollViewer Name="scrollViewer" Width="400" Height="400" Margin="5" HorizontalAlignment="Left"
HorizontalScrollMode="Enabled" VerticalScrollMode="Enabled"
HorizontalScrollBarVisibility="Visible" VerticalScrollBarVisibility="Visible"
IsHorizontalRailEnabled="{Binding IsChecked, ElementName=chkIsHorizontalRailEnabled}"
IsVerticalRailEnabled="{Binding IsChecked, ElementName=chkIsVerticalRailEnabled}">
<Image Source="/Assets/StoreLogo.png" Width="1000" />
</ScrollViewer> </StackPanel>
</Grid>
</Page>
3、演示 ScrollViewer 的 Inertia 特性
Controls/ScrollViewerDemo/Inertia.xaml
<Page
x:Class="Windows10.Controls.ScrollViewerDemo.Inertia"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="using:Windows10.Controls.ScrollViewerDemo"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
mc:Ignorable="d"> <Grid Background="Transparent">
<StackPanel Margin="10 0 10 10"> <CheckBox Name="chkIsScrollInertiaEnabled" Content="IsScrollInertiaEnabled" IsChecked="True" Margin="5" /> <!--
Inertia: 惯性,在触摸模式下,用一个加速度滚动内容,松手后内容会具有惯性滚动效果 IsScrollInertiaEnabled - 是否启用惯性效果,默认值为 true
--> <ScrollViewer Name="scrollViewer" Width="400" Height="400" Margin="5" HorizontalAlignment="Left"
HorizontalScrollMode="Enabled" VerticalScrollMode="Enabled"
HorizontalScrollBarVisibility="Visible" VerticalScrollBarVisibility="Visible"
IsScrollInertiaEnabled="{Binding IsChecked, ElementName=chkIsScrollInertiaEnabled}">
<Image Source="/Assets/StoreLogo.png" Width="1000" />
</ScrollViewer> </StackPanel>
</Grid>
</Page>
4、演示 ScrollViewer 的 Snap 特性
Controls/ScrollViewerDemo/Snap.xaml
<Page
x:Class="Windows10.Controls.ScrollViewerDemo.Snap"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="using:Windows10.Controls.ScrollViewerDemo"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
mc:Ignorable="d"> <Grid Background="Transparent">
<StackPanel Margin="10 0 10 10"> <!--用于设置 ScrollViewer 的 HorizontalSnapPointsType-->
<ComboBox Name="comboBox" SelectedIndex="0" SelectionChanged="comboBox_SelectionChanged" HorizontalAlignment="Left" Margin="5">
<ComboBoxItem>HorizontalSnapPointsType = SnapPointsType.None</ComboBoxItem>
<ComboBoxItem>HorizontalSnapPointsType = SnapPointsType.Optional</ComboBoxItem>
<ComboBoxItem>HorizontalSnapPointsType = SnapPointsType.Mandatory</ComboBoxItem>
</ComboBox> <ScrollViewer x:Name="scrollViewer" Width="400" Height="200" HorizontalAlignment="Left" Margin="5"
HorizontalScrollMode="Enabled" VerticalScrollMode="Enabled"
HorizontalScrollBarVisibility="Visible" VerticalScrollBarVisibility="Visible">
<StackPanel Orientation="Horizontal">
<Image Width="400" Height="200" Stretch="Fill" Source="/Assets/StoreLogo.png" />
<Image Width="400" Height="200" Stretch="Fill" Source="/Assets/StoreLogo.png" />
<Image Width="350" Height="200" Stretch="Fill" Source="/Assets/StoreLogo.png" />
<Image Width="450" Height="200" Stretch="Fill" Source="/Assets/StoreLogo.png" />
<Image Width="400" Height="200" Stretch="Fill" Source="/Assets/StoreLogo.png" /> <TextBox Width="400" Height="200" FontSize="24" Text="message1" Name="txtMsg1" />
<TextBox Width="400" Height="200" FontSize="24" Text="message2" Name="txtMsg2" />
<TextBox Width="400" Height="200" FontSize="24" Text="message3" Name="txtMsg3" />
</StackPanel>
</ScrollViewer> <!--用于演示通过程序定位到 ScrollViewer 内的指定元素-->
<Button Name="btnScroll" Content="滚动到 txtMsg2" Click="btnScroll_Click" Margin="5" /> </StackPanel>
</Grid>
</Page>
Controls/ScrollViewerDemo/Snap.xaml.cs
/*
* Snap: 对齐,在触摸模式下,如果 ScrollViewer 有多个元素,在滚动结束后会定位到其中某一个具体的元素,这就叫对齐
*
* HorizontalSnapPointsType - 水平方向上的对齐行为,Windows.UI.Xaml.Controls.SnapPointsType枚举
* SnapPointsType.None - 不需要对齐,默认值
* SnapPointsType.Optional - 看情况,如果离某个元素很近则对齐此元素
* SnapPointsType.Mandatory - 强制对齐,必须对齐到某一元素
* SnapPointsType.OptionalSingle - 仅对 Zoom 对齐有用(参看 /Controls/ScrollViewerDemo/Zoom.xaml)
* SnapPointsType.MandatorySingle - 仅对 Zoom 对齐有用(参看 /Controls/ScrollViewerDemo/Zoom.xaml)
* 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 Windows10.Controls.ScrollViewerDemo
{
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(object sender, SelectionChangedEventArgs e)
{
if (scrollViewer != null && comboBox != null)
{
switch (comboBox.SelectedIndex)
{
case :
scrollViewer.HorizontalSnapPointsType = SnapPointsType.None;
break;
case :
scrollViewer.HorizontalSnapPointsType = SnapPointsType.Optional;
break;
case :
scrollViewer.HorizontalSnapPointsType = SnapPointsType.Mandatory;
break;
default:
scrollViewer.HorizontalSnapPointsType = SnapPointsType.None;
break;
}
}
} private void btnScroll_Click(object sender, Windows.UI.Xaml.RoutedEventArgs e)
{
// 当 BringIntoViewOnFocusChange 为 true 时,如果 txtMsg2 获得焦点,则 ScrollViewer 会自动滚动到 txtMsg2
txtMsg2.Focus(Windows.UI.Xaml.FocusState.Programmatic);
}
}
}
5、演示 ScrollViewer 的 Zoom 特性
Controls/ScrollViewerDemo/Zoom.xaml
<Page
x:Class="Windows10.Controls.ScrollViewerDemo.Zoom"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="using:Windows10.Controls.ScrollViewerDemo"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
mc:Ignorable="d"> <Grid Background="Transparent">
<StackPanel Margin="10 0 10 10"> <Button Name="bntZoom" Click="bntZoom_Click" Content="放大/缩小到 0.5 倍" Margin="5" /> <!--
Zoom - 放大/缩小 ZoomMode - 是否启用“放大/缩小”功能(Disabled, Enabled),默认值为 Enabled
MaxZoomFactor - 内容放大的最大倍数,默认值 10
MinZoomFactor - 内容放大的最小倍数,默认值 0.1
--> <ScrollViewer Name="scrollViewer" Width="400" Height="400" HorizontalAlignment="Left" Margin="5"
ZoomMode="Enabled" MaxZoomFactor="2" MinZoomFactor="0.5">
<Image Source="/Assets/StoreLogo.png" Width="400" Height="400" />
</ScrollViewer> </StackPanel>
</Grid>
</Page>
Controls/ScrollViewerDemo/Zoom.xaml.cs
using Windows.UI.Xaml;
using Windows.UI.Xaml.Controls; namespace Windows10.Controls.ScrollViewerDemo
{
public sealed partial class Zoom : Page
{
public Zoom()
{
this.InitializeComponent(); this.Loaded += Zoom_Loaded;
} private 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 bntZoom_Click(object sender, RoutedEventArgs e)
{
scrollViewer.ChangeView(null, null, 0.5f);
}
}
}
OK
[源码下载]
背水一战 Windows 10 (47) - 控件(ScrollViewer 特性): Chaining, Rail, Inertia, Snap, Zoom的更多相关文章
- 重新想象 Windows 8 Store Apps (10) - 控件之 ScrollViewer 特性: Chaining, Rail, Inertia, Snap, Zoom
原文:重新想象 Windows 8 Store Apps (10) - 控件之 ScrollViewer 特性: Chaining, Rail, Inertia, Snap, Zoom [源码下载] ...
- 背水一战 Windows 10 (6) - 控件 UI: 字体的自动继承的特性, Style, ControlTemplate
[源码下载] 背水一战 Windows 10 (6) - 控件 UI: 字体的自动继承的特性, Style, ControlTemplate 作者:webabcd 介绍背水一战 Windows 10 ...
- 背水一战 Windows 10 (72) - 控件(控件基类): UIElement - UIElement 的位置, UIElement 的布局, UIElement 的其他特性
[源码下载] 背水一战 Windows 10 (72) - 控件(控件基类): UIElement - UIElement 的位置, UIElement 的布局, UIElement 的其他特性 作者 ...
- 背水一战 Windows 10 (46) - 控件(ScrollViewer 基础): ScrollViewer, ScrollBar, ScrollContentPresenter
[源码下载] 背水一战 Windows 10 (46) - 控件(ScrollViewer 基础): ScrollViewer, ScrollBar, ScrollContentPresenter 作 ...
- 背水一战 Windows 10 (35) - 控件(弹出类): FlyoutBase, Flyout, MenuFlyout
[源码下载] 背水一战 Windows 10 (35) - 控件(弹出类): FlyoutBase, Flyout, MenuFlyout 作者:webabcd 介绍背水一战 Windows 10 之 ...
- 背水一战 Windows 10 (28) - 控件(文本类): TextBox, PasswordBox
[源码下载] 背水一战 Windows 10 (28) - 控件(文本类): TextBox, PasswordBox 作者:webabcd 介绍背水一战 Windows 10 之 控件(文本类) T ...
- 背水一战 Windows 10 (8) - 控件 UI: StateTrigger
[源码下载] 背水一战 Windows 10 (8) - 控件 UI: StateTrigger 作者:webabcd 介绍背水一战 Windows 10 之 控件 UI VisualState 之 ...
- 背水一战 Windows 10 (7) - 控件 UI: VisualState, VisualStateManager, 控件的默认 UI
[源码下载] 背水一战 Windows 10 (7) - 控件 UI: VisualState, VisualStateManager, 控件的默认 UI 作者:webabcd 介绍背水一战 Wind ...
- 背水一战 Windows 10 (68) - 控件(控件基类): UIElement - Pointer 相关事件, Tap 相关事件, Key 相关事件, Focus 相关事件
[源码下载] 背水一战 Windows 10 (68) - 控件(控件基类): UIElement - Pointer 相关事件, Tap 相关事件, Key 相关事件, Focus 相关事件 作者: ...
随机推荐
- 2017/2/10springMVC中文乱码问题
springMVC中文乱码问题 一:从jsp传到后台控制出现的乱码有以下两个方面: 1.当提交方式为get的时候(因为字符拦截器无法拦截get): 修改方法为: 再改工程里的tomcat的配置文件se ...
- Laravel创建自定义 Artisan 控制台命令实例教程
来源:http://laravelacademy.org/post/1374.html 1.入门 Laravel通过Artisan提供了强大的控制台命令来处理非浏览器业务逻辑.要查看Laravel中所 ...
- 引用限定符(c++11)
1.概念 1)下面这种情况将对一个右值调用成员函数.对右值赋值 string s1 = "abc", s2 = "def"; auto n = (s1 + s2 ...
- Comment类型
注释在DOM中是通过Comment类型来表示的. nodeType 8 nodeName #Comment nodeValue 注释的内容 parentNode 可能是Document或Element ...
- #微码分享#C++变参字符串格式化函数format_string
在C和C++中,变参格式化函数虽然非类型安全,但却十分便利,因为得到广泛使用.对于常见的size_t类型要用“%zu”,ssize_t用”%zd“,int64_t用“% ”PRId64,uint64_ ...
- 大压力下Redis参数调整要点
调整以下参数,可以大幅度改善Redis集群的稳定性: 为何大压力下要这样调整? 最重要的原因之一Redis的主从复制,两者复制共享同一线程,虽然是异步复制的,但因为是单线程,所以也十分有限.如果主从间 ...
- 文档/视图(01):第一个Demo
学习文档视图编程的第一个demo,程序比较简单,主要对文档模板,文档,视图等相互关系的一个了解. 功能:菜单添加一个[操作]项,然后新建四份空白文档,点击[操作]之后,在四份空白文档上面各绘制一个Bu ...
- 利用WCF搭建RESTful--纯代码启动
最近学习了这几年忽略了的当前几乎所有的开发技术,有深有浅,而服务层最有兴趣的是RESTfull,看的是java的书.因为不熟悉JSP,于是找了本书细细研读了一次. dotnet的实现也相对简单,网上也 ...
- VHDL基础2
Signals & Variables VHDL 提供了 signal 和 variable 两种对象来处理非静态数据:提供了 constant 和 generic 来处理静态数据. cons ...
- 笔记本真机安装centos7
突然有一天,想要装linux系统,所以就是去装,网上百度说的都很多,而且说来说去都是那几篇,大同小异,所以想通过自己本次装真机的一些经验提供给各位朋友参考一下. 一安装系统: 1先制作启动盘,用个比较 ...