【发布时间】: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