silverlight:ScrollViewer的各种高度研究

本文详细介绍了如何使用XAML创建Silverlight应用程序,并通过CS部分实现用户控件的交互和布局。展示了运行结果及注释,重点在于理解并实现Silverlight应用的基本组件和事件处理。

直接给码:

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

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值