Live Chat Icon For mobile
Live Chat Icon

When I try to add multiple controls to a button it shows an error, how do I add multiple controls to a button?

Platform: WPF| Category: Layouts

Most of UI Elements in WPF can contain only a single child element, therefore, when you add a control to a button, an error stating that the control has a child and only one child can be added to the control is generated. To overcome this error add layouts like StackPanel inside the control and add multiple controls inside that StackPanel.

The following code snippet will cause the error mentioned above.

[XAML]

<Button Height='100'>
            <RadioButton Content='Button1' />
            <RadioButton>Button 2</RadioButton>>
</Button>

A StackPanel can be used inside the button to have multiple controls inside the button.

The following lines of code can be used to overcome the error.

 [XAML]
<Button Height='100'>
	<StackPanel Orientation='Horizontal'>
        <RadioButton Content='Button1'/>
		<RadioButton>Button 2</RadioButton>
    </StackPanel>
</Button>

Share with

Share on twitter
Share on facebook
Share on linkedin

Related FAQs

Couldn't find the FAQs you're looking for?

Please submit your question and answer.