0

Just, tried to add the second button onto GroupBox, knowing that it's GroupBox after all and was surprised that is not allowed by WPF. Am I right?

enter image description here

<Window x:Class="WpfApplication2.MainWindow"
    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:WpfApplication2"
    mc:Ignorable="d"
    Title="MainWindow" Height="768" Width="1024"  MinHeight="768" MinWidth="1024" MaxHeight="1080" MaxWidth="1920">

<Grid x:Name="Grid_1"  ShowGridLines="True">
    <Grid.RowDefinitions>
        <RowDefinition Height="80*"/>
        <RowDefinition Height="512*"/>
        <RowDefinition Height="160*"/>
    </Grid.RowDefinitions>
    <Image x:Name="image"  Grid.Row="1" Source="Resources/truck.png" />
    <Grid  Grid.Row="2">
        <Grid.ColumnDefinitions>
            <ColumnDefinition Width="112*"/>
            <ColumnDefinition Width="247*"/>
            <ColumnDefinition Width="247*"/>
            <ColumnDefinition Width="247*"/>
            <ColumnDefinition Width="118*"/>
        </Grid.ColumnDefinitions>
        <GroupBox x:Name="groupBox1" Header="Truck1" FontSize="16" Background="BlanchedAlmond" Grid.Column="1" >
            <Button x:Name="button" Content="Start1" HorizontalAlignment="Left" Margin="154,6,0,0" VerticalAlignment="Top" Width="75"/>
        </GroupBox>
        <GroupBox x:Name="groupBox2" Grid.Column="2" Header="Truck2" FontSize="16" Background="BlanchedAlmond"   />
        <GroupBox x:Name="groupBox3" Grid.Column="3" Header="Truck3" FontSize="16" Background="BlanchedAlmond"   />
    </Grid>





</Grid>

Msorich
  • 113
  • 1
  • 10
  • 6
    As a ContentControl, GroupBox can only have a single child (in its Content property). Add an appropriate Panel for multiple child elements. – Clemens Aug 16 '18 at 17:58
  • 2
    Add another control such as a `Grid` or a `StackPanel` inside it if you want to add more controls. – Sach Aug 16 '18 at 18:02
  • That sounds funny. Why does it have in its name a word "Group". The story has no records. It's not useful control. Isn't it? – Msorich Aug 16 '18 at 18:45
  • 2
    It's useful in that it adds a decorator around the item you want to treat as a group. It just so happens that the item you want to treat as a group is a collection of things, and so it requires a control that inherits from `Panel`. – Jason Tyler Aug 16 '18 at 19:27
  • Possible duplicate of [GroupBox in WPF can only contain one element?](https://stackoverflow.com/questions/1356036/groupbox-in-wpf-can-only-contain-one-element) – Suresh Aug 23 '18 at 18:50

0 Answers0