Skip to content

Seeking clarification on RadioButton + ControlTemplate + Content documentation #33829

@beeradmoore

Description

@beeradmoore

In the latest docs for RadioButton it says

When a ControlTemplate is applied to a RadioButton, a View can be assigned to the RadioButton.Content property on all platforms. For more information, see Redefine RadioButton appearance.

Doing so this produces a lot of warnings like this.

Microsoft.Maui.Controls.RadioButton: Warning: Warning - iOS does not support View as the Content property of RadioButton; the return value of the ToString() method will be displayed instead.

and

Microsoft.Maui.Controls.RadioButton: Warning: Warning - Android does not support View as the Content property of RadioButton; the return value of the ToString() method will be displayed instead.

This only appears when I set ControlTemplate AND Content when content is a View.

eg.

<RadioButton ControlTemplate="{StaticResource MyTemplate}">
    <RadioButton.Content>
        <Label Text="Test label" />
    </RadioButton.Content>
</RadioButton>

If I only set ControlTemplate OR Content (or ControlTemplate with a string for Content) it does not cause an issue.

eg.

<RadioButton ControlTemplate="{StaticResource MyTemplate}" Content="Test text" />

...

<RadioButton>
    <RadioButton.Content>
        <Label Text="Test label" />
    </RadioButton.Content>
</RadioButton>

This seems counter to what the documentation says. It almost seems like the documentation is wrong and "can be assigned" should be "can't be assigned"

This message seems to be coming from the ContentAsString method in RadioButton.cs. Oddly enough when you look at the two places it is called one is checking for ContentTemplate to be null and the other is checking for it to not be null.

This occours in .NET 9 (MAUI 9.0.120, limited to .NET SDK 9.0.305) and .NET 10 (MAUI 10.0.30, limited to .NET SDK 10.0.102).

Reproduction repo: https://github.com/beeradmoore/maui-issue-RadioButtonControlTemplateContent

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions