这应该很简单,但我想我错过了一些东西。
我有一个包含网格和2条路径的简单用户控件。
我想让这个用户控件可伸缩到任何所需的大小,保持路径的相对位置(原始作品有更多的动画路径)。
<UserControl
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
x:Class="test.MainPage">
<Grid x:Name="LayoutRoot" Background="White" Width="400" Height="400">
<Path Fill="White" Stretch="Fill" Stroke="Black" Height="101"
Margin="49.5,49.5,199.5,0" VerticalAlignment="Top"
Data="M50,50 L100,50 L150,50 L200,50 L200,100 L150,100 L150,150 L100,150 L100,100 L50,100 z"/>
<Path Fill="White" Stretch="Fill" Stroke="Black"
Margin="0,150.5,48.5,148.5"
Data="M50,50 L100,50 L150,50 L200,50 L200,100 L150,100 L150,150 L100,150 L100,100 L50,100 z"
HorizontalAlignment="Right" Width="151"/>
</Grid>
</UserControl>
感谢您的帮助。
答案 0 :(得分:6)
将LayoutRoot更改为ViewBox会在控件调整大小时调整路径大小:
<Viewbox x:Name="LayoutRoot" Stretch="Fill">
<Grid Width="400" Height="400">
<Path Fill="White" Stretch="Fill" Stroke="Black" Height="101"
Margin="49.5,49.5,199.5,0" VerticalAlignment="Top"
Data="M50,50 L100,50 L150,50 L200,50 L200,100 L150,100 L150,150 L100,150 L100,100 L50,100 z"/>
<Path Fill="White" Stretch="Fill" Stroke="Black"
Margin="0,150.5,48.5,148.5"
Data="M50,50 L100,50 L150,50 L200,50 L200,100 L150,100 L150,150 L100,150 L100,100 L50,100 z"
HorizontalAlignment="Right" Width="151"/>
</Grid>
</Viewbox>
编辑:回复评论。
我在Silverlight 3中尝试了它,它使用以下标记,允许数字在浏览器窗口大小更改时重新缩放:
<UserControl
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"
xmlns:controlsToolkit="clr-namespace:System.Windows.Controls;assembly=System.Windows.Controls.Toolkit"
x:Class="SLViewbox.UserControl1"
>
<Grid x:Name="LayoutRoot">
<controlsToolkit:Viewbox>
<Grid Width="400" Height="400">
<Path Fill="White" Stretch="Fill" Stroke="Black" Height="101"
Margin="49.5,49.5,199.5,0" VerticalAlignment="Top"
Data="M50,50 L100,50 L150,50 L200,50 L200,100 L150,100 L150,150 L100,150 L100,100 L50,100 z"/>
<Path Fill="White" Stretch="Fill" Stroke="Black"
Margin="0,150.5,48.5,148.5"
Data="M50,50 L100,50 L150,50 L200,50 L200,100 L150,100 L150,150 L100,150 L100,100 L50,100 z"
HorizontalAlignment="Right" Width="151"/>
</Grid>
</controlsToolkit:Viewbox>
</Grid>
</UserControl>
用户控件嵌入在页面中:
<UserControl
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="clr-namespace:SLViewbox" xmlns:d="http://schemas.microsoft.com/expression/blend/2008" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
x:Class="SLViewbox.MainPage"
mc:Ignorable="d">
<Grid x:Name="LayoutRoot" Background="White">
<local:UserControl1 />
</Grid>
</UserControl>