【问题标题】:Using Browser ScrollBars for Silverlight4 App为 Silverlight4 应用程序使用浏览器滚动条
【发布时间】:2011-03-09 13:56:37
【问题描述】:

我正在尝试使我的 Silverlight 应用程序的行为与任何其他 Web 应用程序一样进行布局。

我关注了this thread,它展示了当应用占用的区域小于客户端窗口时,如何扩展应用以填充可用空间。

但是,我似乎找不到相反的代码。也就是说,当我的应用程序变得大于浏览器的客户区时,我希望浏览器显示适当的滚动条。目前,上面的代码只是将应用程序裁剪为浏览器的大小。

这是一个简单的示例应用:

<UserControl x:Class="SilverlightWidthAndHeight.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"
             HorizontalAlignment="Stretch"
             VerticalAlignment="Stretch"
    d:DesignHeight="300" d:DesignWidth="400">

    <Grid x:Name="LayoutRoot"
          HorizontalAlignment="Stretch"
          VerticalAlignment="Stretch">
        <Grid.RowDefinitions>
            <RowDefinition Height="Auto" />
            <RowDefinition Height="*" />
            <RowDefinition Height="Auto" />
        </Grid.RowDefinitions>        

        <Rectangle Grid.Row="0"
                   Fill="Blue" />
        <TextBlock Grid.Row="0" 
                   Foreground="White"
                   FontSize="20"
                   FontWeight="Bold"
                   Margin="5"
                   Text="Header" />

        <Rectangle Grid.Row="1"
                   Fill="Red" />

        <StackPanel Grid.Row="1"
                        Orientation="Horizontal">
            <TextBlock x:Name="txtMiddleRow" 
                           Foreground="White"
                           FontSize="28"
                           Text="Middle Row" />

            <Button x:Name="btnGrow"
                        Content="Grow"
                        VerticalAlignment="Center"
                        Margin="5" />
        </StackPanel>


        <Rectangle Grid.Row="2"
                   Fill="Blue" />
        <TextBlock Grid.Row="2" 
                   Foreground="White"
                   FontSize="20"
                   FontWeight="Bold"
                   Margin="5"
                   Text="Footer" />

    </Grid>
</UserControl>

如您所见,它适当地填充了空间:

但是如果我按下“增长”按钮来增加 TextBlock 的字体大小:

我知道我可以将所有内容包装在一个 ScrollViewer 中,但是在浏览器滚动条的左侧立即有一个滚动条看起来像是一种黑客行为。

谢谢,
wTs

【问题讨论】:

  • 隐藏浏览器滚动条怎么样?然后你可以只使用 SL 滚动查看器或其他任何东西。

标签: silverlight silverlight-4.0 resize


【解决方案1】:

您要求的是silverlight 自行调整大小。这将需要你做很多工作。您将需要编写知道您的应用程序何时变大的代码,并且它将缩放保存您的 silverlight 应用程序的 html 对象。

例如,在 layoutroot 上为 layoutchange 设置一个事件,然后从代码中设置 silverlight 应用程序的 height 属性。看看如何操作 html 并从 silverlight here 调用 javascript。

【讨论】:

    猜你喜欢
    • 2011-12-24
    • 1970-01-01
    • 2019-03-10
    • 2010-09-06
    • 2018-08-31
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2010-11-15
    相关资源
    最近更新 更多