• silverlight:ScrollViewer的各种高度研究


    直接给码:

    <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部分:

    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事件中才能正确获得。

  • 相关阅读:
    work_7_Boolean和boolean,基本类型和包装类型
    work_06_服务器上传图片错误
    work_05_64未随机id生成器
    work_04_谷歌验证码工具Kaptcha
    vue.js_13_vue的搭建
    每日一java(割草机)
    work_03_常见jq问题处理
    work_02_css样式
    java 27
    java 27
  • 原文地址:https://www.cnblogs.com/yjmyzz/p/2310245.html
Copyright © 2020-2023  润新知