Question

I'm trying to make a GroupBox with a few (radio)buttons in it. But in the samples i'm using checkbox.

<GroupBox Header="Aðgerðir" HorizontalAlignment="Left" VerticalAlignment="Bottom" Margin="270,0,0,178" Height="106" Width="176">
    <CheckBox Content="CheckBox" HorizontalAlignment="Left" VerticalAlignment="Top"/>
    <CheckBox Content="CheckBox" HorizontalAlignment="Left" VerticalAlignment="Bottom"/>
</GroupBox>

The above does not work and visual studio says "Invalid Markup".

This here works fine though

<GroupBox Header="Aðgerðir" HorizontalAlignment="Left" VerticalAlignment="Bottom" Margin="270,0,0,178" Height="106" Width="176">
    <CheckBox Content="CheckBox" HorizontalAlignment="Left" VerticalAlignment="Top"/>
</GroupBox>

I don't get it. It says "Content can only be set once" if i run the debugger, but erasing the Content part of the checkbox seems to have no effect.

Était-ce utile?

La solution

The content of the GroupBox can only be set once, meaning that it can only have a single control inside it. If you want to two radio button, place them in a stack panel or a grid.

GroupBox Overview

<GroupBox Header="Aðgerðir" HorizontalAlignment="Left" VerticalAlignment="Bottom" Margin="270,0,0,178" Height="106" Width="176">
    <StackPanel>
        <CheckBox Content="CheckBox" HorizontalAlignment="Left" VerticalAlignment="Top"/>
        <CheckBox Content="CheckBox" HorizontalAlignment="Left" VerticalAlignment="Bottom"/>
    </StackPanel>    
</GroupBox>
Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top