zoukankan      html  css  js  c++  java
  • 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事件中才能正确获得。

  • 相关阅读:
    文化课随笔
    微积分与无穷级数
    [康复计划]-数论基础
    [Codeforces]CF742(Div.2)A-E
    第一次个人编程作业的过程和想法
    第一次个人编程作业
    Python命令行参数及文件读出写入
    第一次个人编程作业
    第一次个人编程作业
    第一次博客作业
  • 原文地址:https://www.cnblogs.com/yjmyzz/p/2310245.html
Copyright © 2011-2022 走看看