在背景图上写控件时,控制所写控件的相对布局不变,WPF 控件的相对布局启动:
未按等比例设置的放大效果,可以看出我们事先绘制的红色框线已经偏离原先在内的Button
按等比例缩放效果:
可以看出,等比例缩放效果,是一直红色框线和Butong的位置保持相对不变未按等比例缩放<Window x:Class="WpfApp1.Window3"
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"
xmlns:local="clr-namespace:WpfApp1"
mc:Ignorable="d"
Title="Window3" Height="350" Width="560" WindowStyle="None" ResizeMode="NoResize">
<Grid>
<Grid.Background>
<ImageBrush ImageSource="bg.png"/>
</Grid.Background>
<Button Content="Button" HorizontalAlignment="Left" Margin="402,249,0,0" VerticalAlignment="Top" Width="62" RenderTransformOrigin="0.471,0.289" Height="24"/>
<Button Content="最大化" Click="Button_Click" HorizontalAlignment="Left" Margin="87,142,0,0" VerticalAlignment="Top" Width="75"/>
<Button Content="等比例缩放窗口" Click="Button_Click_1" HorizontalAlignment="Left" Margin="87,221,0,0" VerticalAlignment="Top" Width="104" Height="29"/>
</Grid>
</Window>
等比例缩放:<Window x:Class="WpfApp1.Window4"
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"
xmlns:local="clr-namespace:WpfApp1"
mc:Ignorable="d"
Title="Window3" Height="350" Width="560" WindowStyle="None" ResizeMode="NoResize">
<Grid>
<Grid.Background>
<ImageBrush ImageSource="bg.png"/>
</Grid.Background>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="450*"></ColumnDefinition>
<ColumnDefinition Width="80*"></ColumnDefinition>
<ColumnDefinition Width="100*"></ColumnDefinition>
</Grid.ColumnDefinitions>
<Grid.RowDefinitions>
<RowDefinition Height="760*"></RowDefinition>
<RowDefinition Height="100*"></RowDefinition>
<RowDefinition Height="230*"></RowDefinition>
</Grid.RowDefinitions>
<Button Content="Button" Grid.Column="1" Grid.Row="1" Margin="5"/>
<Button Content="最大化" Click="Button_Click" HorizontalAlignment="Left" Margin="87,142,0,0" VerticalAlignment="Top" Width="75"/>
</Grid>
</Window>
评论