前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >silverlight:ScrollViewer的各种高度研究

silverlight:ScrollViewer的各种高度研究

作者头像
菩提树下的杨过
发布2018-01-24 10:32:22
5550
发布2018-01-24 10:32:22
举报

直接给码:

代码语言:javascript
复制
<UserControl x:Class="SilverlightApplication1.MainPage"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
    xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
    mc:Ignorable="d"
    Width="640" Height="300">

    <Grid x:Name="LayoutRoot" Background="LightBlue">
        <Grid.RowDefinitions>
            <RowDefinition></RowDefinition>
            <RowDefinition Height="Auto" MinHeight="30"></RowDefinition>
        </Grid.RowDefinitions>
        <ScrollViewer Name="sv" VerticalScrollBarVisibility="Visible" LostMouseCapture="sv_LostMouseCapture">
            <Border Background="Azure" BorderBrush="Black" Margin="5" BorderThickness="1" Height="400"></Border>
        </ScrollViewer>
        <StackPanel Grid.Row="1" VerticalAlignment="Center" Orientation="Horizontal" HorizontalAlignment="Center">
            <Button Content="Test" Click="Button_Click" HorizontalAlignment="Center" Padding="10,0"></Button>
            <TextBlock x:Name="tb1" Margin="10,0,0,0"></TextBlock>
        </StackPanel>
    </Grid>
</UserControl>

  cs部分:

代码语言:javascript
复制
using System.Windows;
using System.Windows.Controls;

namespace SilverlightApplication1
{
    public partial class MainPage : UserControl
    {
        public MainPage()
        {
            InitializeComponent();
        }

        private void Button_Click(object sender, RoutedEventArgs e)
        {

            ShowHeight();
        }

        private void sv_LostMouseCapture(object sender, System.Windows.Input.MouseEventArgs e)
        {
            ShowHeight();
        }

        void ShowHeight()
        {
            tb1.Text = string.Format("ActualHeight:{0},VerticalOffset:{1},ViewportHeight:{2},ExtentHeight:{3}", sv.ActualHeight, sv.VerticalOffset, sv.ViewportHeight, sv.ExtentHeight);
        }
    }
}

  运行结果截图:(已经在图上直接加了注释)

注:ExtentHeight只能在LostMouseCapture事件中才能正确获得。

本文参与 腾讯云自媒体分享计划,分享自作者个人站点/博客。
原始发表:2012-01-02 ,如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 作者个人站点/博客 前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体分享计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档