控制WPF中的对齐方式

时间:2013-01-28 05:10:18

标签: wpf panel

我在WPF中设计了一个窗口,左边有一个图像,图像旁边有两个按钮。 我将WindowState设置为Maximized

但是在运行应用程序时,间隙b / w控件增加了。我希望在设计时使用对齐方式。在windows application中,它会在wpf中与控件自动对齐。

请让我这样做,我是wpf的新手。 Panels可以解决此问题吗?

Samplle

<Window x:Class="AnalogCalibrationTool.Window1"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="Analog Hardware Calibration Tool" 
    Height="500" 
    Width="700" 
    WindowStartupLocation="CenterScreen" 
    WindowStyle="SingleBorderWindow" 
    WindowState="Maximized" 
    ResizeMode="NoResize" SnapsToDevicePixels="True">
<Grid>
    <Image HorizontalAlignment="Left" Margin="84.436,164.428,0,147.763" Name="image1" Stretch="Fill" Width="200" />
    <Button Height="23" Margin="326.634,0,276.639,147.763" Name="button1" VerticalAlignment="Bottom">Button</Button>
    <Button Height="29.997" HorizontalAlignment="Right" Margin="0,0,184.426,144.264" Name="button2" VerticalAlignment="Bottom" Width="75">Button</Button>
</Grid>
</Window>

1 个答案:

答案 0 :(得分:0)

你可以试试这个:

<Grid>
    <Grid.ColumnDefinitions>
        <ColumnDefinition Width="Auto"/>
        <ColumnDefinition Width="*"/>
    </Grid.ColumnDefinitions>
    <Rectangle Name="image1" Width="200" Grid.Column="0" Fill="Aqua"  />
    <StackPanel Grid.Column="1" HorizontalAlignment="Left">
        <Button Name="button1" Height="23" Width="60" Content="Button1"/>
        <Button Name="button2" Height="23" Width="60" Content="Button2"/>
    </StackPanel>
</Grid>

在示例中,矩形用作图像的假。