将堆栈面板划分为3个相等的大小

时间:2017-06-01 14:37:59

标签: c# wpf

我正在尝试使用左侧组框(停靠在左侧),中间的图像和右侧的组框(停靠在右侧)。

我无法弄清楚我做错了什么,但它编译成这样:My WPF Program

我尝试使用ColumnDefinitions而没有成功..请帮助我

 <Grid>
    <Grid.ColumnDefinitions>
        <ColumnDefinition Width="*" />
        <ColumnDefinition Width="*" />
        <ColumnDefinition Width="*" />
    </Grid.ColumnDefinitions>

    <StackPanel Orientation="Horizontal" DockPanel.Dock="Top" >
    <GroupBox x:Name="RightGroupBox" Grid.Column="1" BorderBrush="#515151" BorderThickness="1" Header="Right Tools" FontSize="18" Foreground="White" Width="369" Margin="0,10,0,0">
        <StackPanel x:Name="ToolsStackRight" Orientation="Vertical" Margin="0,10,-2,0">
            <amob:AmobComboBox x:Name="cmbTool10" Width="300" Margin="0,0,35,20" SelectionChanged="cmbTool5_SelectionChanged"/>
            <amob:AmobComboBox x:Name="cmbTool9" Width="300" Margin="0,0,35,20" SelectionChanged="cmbTool4_SelectionChanged"/>
            <amob:AmobComboBox x:Name="cmbTool8" Width="300" Margin="0,0,35,20" SelectionChanged="cmbTool3_SelectionChanged"/>
            <amob:AmobComboBox x:Name="cmbTool7" Width="300" Margin="0,0,35,20" SelectionChanged="cmbTool2_SelectionChanged"/>
            <amob:AmobComboBox x:Name="cmbTool6" Width="300" Margin="0,0,35,20" SelectionChanged="cmbTool1_SelectionChanged"/>
        </StackPanel>
    </GroupBox>

    <Image HorizontalAlignment="Center" Grid.Column="2" Name="ToolsImageLeft" Height="256" Width="294" Source="/AMOB_CNC;component/Resources/5tolls_3d.png" RenderTransformOrigin="0.5,0.5" Margin="40,0,0,0"></Image>

    <GroupBox x:Name="LeftGroupBox" Grid.Column="3" BorderBrush="#515151" BorderThickness="1" Header="Right Tools" FontSize="18" Foreground="White" Width="369" Margin="0,10,0,0">
        <StackPanel x:Name="ToolStackLeft" Orientation="Vertical" Margin="0,10,-2,0" >
            <amob:AmobComboBox x:Name="cmbTool5" Width="300" Margin="0,0,35,20" SelectionChanged="cmbTool5_SelectionChanged"/>
            <amob:AmobComboBox x:Name="cmbTool4" Width="300" Margin="0,0,35,20" SelectionChanged="cmbTool4_SelectionChanged"/>
            <amob:AmobComboBox x:Name="cmbTool3" Width="300" Margin="0,0,35,20" SelectionChanged="cmbTool3_SelectionChanged"/>
            <amob:AmobComboBox x:Name="cmbTool2" Width="300" Margin="0,0,35,20" SelectionChanged="cmbTool2_SelectionChanged"/>
            <amob:AmobComboBox x:Name="cmbTool1" Width="300" Margin="0,0,35,20" SelectionChanged="cmbTool1_SelectionChanged"/>
        </StackPanel>
    </GroupBox>
</StackPanel>
</Grid>

1 个答案:

答案 0 :(得分:1)

Grid内的StackPanel弄乱了布局。删除它并修复元素上的​​Grid.Column数字(数字从0开始)

<Grid>
    <Grid.ColumnDefinitions>
        <ColumnDefinition Width="*" />
        <ColumnDefinition Width="*" />
        <ColumnDefinition Width="*" />
    </Grid.ColumnDefinitions>

    <GroupBox x:Name="RightGroupBox" Grid.Column="0" BorderBrush="#515151" BorderThickness="1" Header="Right Tools" FontSize="18" Foreground="White" Width="369" Margin="0,10,0,0">
        <StackPanel x:Name="ToolsStackRight" Orientation="Vertical" Margin="0,10,-2,0">
            <amob:AmobComboBox x:Name="cmbTool10" Width="300" Margin="0,0,35,20" SelectionChanged="cmbTool5_SelectionChanged"/>
            <amob:AmobComboBox x:Name="cmbTool9" Width="300" Margin="0,0,35,20" SelectionChanged="cmbTool4_SelectionChanged"/>
            <amob:AmobComboBox x:Name="cmbTool8" Width="300" Margin="0,0,35,20" SelectionChanged="cmbTool3_SelectionChanged"/>
            <amob:AmobComboBox x:Name="cmbTool7" Width="300" Margin="0,0,35,20" SelectionChanged="cmbTool2_SelectionChanged"/>
            <amob:AmobComboBox x:Name="cmbTool6" Width="300" Margin="0,0,35,20" SelectionChanged="cmbTool1_SelectionChanged"/>
        </StackPanel>
    </GroupBox>

    <Image HorizontalAlignment="Center" Grid.Column="1" Name="ToolsImageLeft" Height="256" Width="294" Source="/AMOB_CNC;component/Resources/5tolls_3d.png" RenderTransformOrigin="0.5,0.5" Margin="40,0,0,0"></Image>

    <GroupBox x:Name="LeftGroupBox" Grid.Column="2" BorderBrush="#515151" BorderThickness="1" Header="Right Tools" FontSize="18" Foreground="White" Width="369" Margin="0,10,0,0">
        <StackPanel x:Name="ToolStackLeft" Orientation="Vertical" Margin="0,10,-2,0" >
            <amob:AmobComboBox x:Name="cmbTool5" Width="300" Margin="0,0,35,20" SelectionChanged="cmbTool5_SelectionChanged"/>
            <amob:AmobComboBox x:Name="cmbTool4" Width="300" Margin="0,0,35,20" SelectionChanged="cmbTool4_SelectionChanged"/>
            <amob:AmobComboBox x:Name="cmbTool3" Width="300" Margin="0,0,35,20" SelectionChanged="cmbTool3_SelectionChanged"/>
            <amob:AmobComboBox x:Name="cmbTool2" Width="300" Margin="0,0,35,20" SelectionChanged="cmbTool2_SelectionChanged"/>
            <amob:AmobComboBox x:Name="cmbTool1" Width="300" Margin="0,0,35,20" SelectionChanged="cmbTool1_SelectionChanged"/>
        </StackPanel>
    </GroupBox>
</Grid>