Blend 4 - Viewbox [英] Blend 4 - Viewbox
问题描述
Hiya
刚开始学习Blend / Silverlight并尝试了解视图框的工作方式,我的理解是,当我调整网页大小时,我可以获得图形/文字自动调整大小,所以使用代码:
Just starting to learn Blend / Silverlight and trying to understand how the viewbox works, my understanding is that as I resize a web page I can get the graphics / text to automatically resize with it, so with the code:
< UserControl
xmlns =" http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x =" http://schemas.microsoft.com/winfx/2006/xaml"
x:Class =" SilverlightApplication1.MainPage"
宽度= QUOT; 800"高度="600">
< Viewbox Width =" 800"高度= QUOT; 600"的HorizontalAlignment = QUOT;中心" VerticalAlignment =" Center"&
&NBSP;&NBSP;&NBSP; < Grid Height =" 600"宽度= QUOT; 800"背景="白色">
&NBSP;&NBSP;&NBSP; &NBSP;&NBSP;&NBSP; < Rectangle Fill =" Black"的HorizontalAlignment = QUOT;左"高度= QUOT; 138"余量= QUOT; 8,8,0,0"行程="黑色" VerticalAlignment = QUOT;陀螺" Width =" 358" />
&NBSP;&NBSP;&NBSP; &NBSP;&NBSP;&NBSP; < TextBlock HorizontalAlignment =" Left" TextWrapping = QUOT;包覆与QUOT; Text =" Text box" VerticalAlignment = QUOT;陀螺"余量= QUOT; 8,164,0,0" FontSize =" 26.667" />
&NBSP;&NBSP;&NBSP; < / Grid>
< / Viewbox>
< / UserControl>
<UserControl
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
x:Class="SilverlightApplication1.MainPage"
Width="800" Height="600">
<Viewbox Width="800" Height="600" HorizontalAlignment="Center" VerticalAlignment="Center">
<Grid Height="600" Width="800" Background="White">
<Rectangle Fill="Black" HorizontalAlignment="Left" Height="138" Margin="8,8,0,0" Stroke="Black" VerticalAlignment="Top" Width="358"/>
<TextBlock HorizontalAlignment="Left" TextWrapping="Wrap" Text="Text box" VerticalAlignment="Top" Margin="8,164,0,0" FontSize="26.667"/>
</Grid>
</Viewbox>
</UserControl>
我希望文本和黑色矩形会随着我改变窗口大小而调整大小,但它不会。
I was hoping that the text and black rectange would resize as I changed the window size, but it doesnt.
希望有人能告诉我我的方式错误。
Hoping that someone can show me the error of my ways.
谢谢
推荐答案
您在视图框内的网格具有明确的高度/宽度,我相信您需要将其删除并将其设置为在视图框内拉伸。您可能还需要删除视图框的显式高度/宽度。与usercontrol本身相同。 这是一个
示例,它使用浏览器窗口调整大小并填充整个区域:
Your grid inside the viewbox has an explicit height/width, I believe you need to remove that and set it to stretch inside the viewbox. You may also need to remove the explicit height/width of the viewbox. Same with the usercontrol itself. Here is an example that resizes with the browser window and fills the entire area:
<UserControl
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
x:Class="SilverlightApplication13.MainPage">
<Viewbox>
<Grid x:Name="LayoutRoot" Background="#FFFFBABA" Height="480" Width="640">
<Button Content="Button" HorizontalAlignment="Left" Height="31" Margin="52,41,0,0" VerticalAlignment="Top" Width="48"/>
<Button Content="Button" HorizontalAlignment="Right" Height="45" Margin="0,0,126,72" VerticalAlignment="Bottom" Width="46"/>
</Grid>
</Viewbox>
</UserControl>
这篇关于Blend 4 - Viewbox的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!