Windows 8 Store Apps学习(9) ScrollViewer控件基础

介绍

重新想象 Windows 8 Store Apps 之 ScrollViewer

演示 ScrollViewer 的基本应用

演示 ScrollBar 的基本应用

演示 ScrollContentPresenter 的基本应用

示例

1、 ScrollViewer 的基本应用

ScrollViewer/Demo.xaml

<Page
    x:Class="XamlDemo.Controls.ScrollViewer.Demo"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:local="using:XamlDemo.Controls.ScrollViewer"
    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="120 0 0 0">

            <TextBlock Name="lblMsg" />

            <!--
                ScrollViewer - 滚动视图控件
                    Content - 滚动视图内的内容
                    IsDeferredScrollingEnabled - 是否启用延迟滚动,在滚动内容过多时,启用延迟混动可以改善性能,默认值为 false
                    HorizontalScrollMode - 水平滚动条的行为方式,Windows.UI.Xaml.Controls.ScrollMode枚举(Disabled, Enabled, Auto)
                    VerticalScrollMode - 垂直滚动条的行为方式
                    HorizontalScrollBarVisibility - 水平滚动条的可见性,Windows.UI.Xaml.Controls.ScrollBarVisibility枚举(Disabled, Auto, Hidden, Visible)
                    VerticalScrollBarVisibility - 垂直滚动条的可见性
                    ViewChanged - 发生滚动时所触发的事件
            -->
            <ScrollViewer Name="scrollViewer" Width="400" Height="400" Margin="0 10 0 0" HorizontalAlignment="Left"
                          IsDeferredScrollingEnabled="False"
                          ViewChanged="scrollViewer_ViewChanged_1"
                          HorizontalScrollMode="Enabled" VerticalScrollMode="Enabled"
                          HorizontalScrollBarVisibility="Visible" VerticalScrollBarVisibility="Visible">
                <ScrollViewer.Content>
                    <Image Source="/Assets/Logo.png" Width="1000" />
                </ScrollViewer.Content>
            </ScrollViewer>

            <StackPanel Orientation="Horizontal">
                <!--使 ScrollViewer 里的内容滚动到相对于 ScrollViewer 居中-->
                <Button Content="居中" Click="Button_Click_1" />
            </StackPanel>

        </StackPanel>
    </Grid>
</Page>

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);
        }
    }
}

以上是小编为您精心准备的的内容,在的博客、问答、公众号、人物、课程等栏目也有的相关内容,欢迎继续使用右上角搜索按钮进行搜索scrollviewer
, scrollview
, text
, 滚动
, 加入scrollview显示
, 加入scrollview不显示
, 滚动动画scrollviewer
, 偏移
, scrollview 
, scrollview滑动冲突
, scrollview滑动距离
, 可滚动
, scrollview反弹
水平滚动控件
,以便于您获取更多的相关知识。

时间: 2024-08-03 22:51:55

Windows 8 Store Apps学习(9) ScrollViewer控件基础的相关文章

Windows 8 Store Apps学习(10) ScrollViewer控件特性

介绍 重新想象 Windows 8 Store Apps 之 ScrollViewer Chaining - 锁链 Rail - 轨道 Inertia - 惯性 Snap - 对齐 Zoom - 缩放 示例 1.演示 ScrollViewer 的 Chaining 特性 ScrollViewer/Chaining.xaml <Page x:Class="XamlDemo.Controls.ScrollViewer.Chaining" xmlns="http://sche

Windows 8 Store Apps学习(11) ListView控件和 GridView控件

介绍 重新想象 Windows 8 Store Apps 之 ListView 和 GridView ListView - 列表控件 GridView - 网格控件 示例 1.ListView 的 Demo ListViewDemo.xaml <Page x:Class="XamlDemo.Controls.ListViewDemo" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation&quo

Windows 8 Store Apps学习(12) GridView控件特性

GridView控件特性: 拖动项, 项尺寸可变, 分组显示 介绍 重新想象 Windows 8 Store Apps 之 GridView 拖动项 - 在 GridView 内拖动 item 以对 item 排序, 拖动 item 到 GridView 外的指定位置以删除 item 项尺寸可变 - 指定 GirdView 中每个 item 所占尺寸 分组显示 - 分组显示集合数据 示例 1.演示如何在 GridView 内拖动 item 以对 item 排序,以及如何拖动 item 到 Gri

Windows 8 Store Apps学习(7) 布局控件

Canvas, Grid, StackPanel, VirtualizingS 介绍 重新想象 Windows 8 Store Apps 之布局控件 Canvas - 绝对定位式布局 Grid - 网格式布局 StackPanel - 流式布局 VirtualizingStackPanel - 仅能用于 ItemsControl WrapGrid - 仅能用于 ItemsControl VariableSizedWrapGrid - 用于 Wrap 子元素集合 示例 1.Canvas 的 Dem

Windows 8 Store Apps学习(6) 媒体控件

Image, MediaElement 介绍 重新想象 Windows 8 Store Apps 之媒体控件 Image - 图片控件 MediaElement - 播放视频或音频的控件 示例 1.Image 的 Demo ImageDemo.xaml <Page x:Class="XamlDemo.Controls.ImageDemo" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation&q

Windows 8 Store Apps学习(5) 集合控件

ComboBox, ListBox, FlipView, ItemsContr 介绍 重新想象 Windows 8 Store Apps 之集合控件 ComboBox - 下拉框 ListBox - 列表框 FlipView - 滑动视图控件 ItemsControl ItemsPresenter - ItemsPresenter 用来呈现 ItemsControl 的 Items 示例 1.ComboBox 的 Demo ComboBoxDemo.xaml <Page x:Class="

Windows 8 Store Apps学习(4) 提示控件和范围控件

提示控件: ProgressRing; 范围控件: ProgressBar, Slider 介绍 重新想象 Windows 8 Store Apps 之提示控件 ProgressRing - 进度圈控件 重新想象 Windows 8 Store Apps 之范围控件 ProgressBar - 进度条控件 Slider - 滑动条控件 示例 1.ProgressRing 的 Demo ProgressRingDemo.xaml <Page x:Class="XamlDemo.Control

Windows 8 Store Apps学习(3) 内容控件

ToolTip, Frame, AppBar, ContentControl 介绍 重新想象 Windows 8 Store Apps 之内容控件 ToolTip - 提示框控件 Frame - 框架控件,用于导航内容 AppBar - 应用程序栏控件 ContentControl ContentPresenter - ContentPresenter 用来呈现 ContentControl 的 Content 重新想象 Windows 8 Store Apps 之容器控件 Border - 边

Windows 8 Store Apps学习(2) 按钮控件

Button, HyperlinkButton, RepeatButton 介绍 重新想象 Windows 8 Store Apps 之按钮控件 Button - 按钮控件 HyperlinkButton - 超链按钮 RepeatButton - 按住后会重复执行单击操作的按钮 ToggleButton - 可切换状态的按钮 RadioButton - 单选框控件 CheckBox - 复选框控件 ToggleSwitch - 状态切换控件 示例 1.Button 的 Demo ButtonD