-
Notifications
You must be signed in to change notification settings - Fork 706
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
RadioButtons: Custom ItemTemplate is not automatically prefaced by a RadioButton if it doesn't specify one itself as its root element #3159
Comments
It seems like the current functionality might be by design. How do you change the look of the radio button itself otherwise? |
@robloo The issue is that the current impementation makes the If you want to style the RadioButton "icon" itself, my guess was you could do it like this: <muxc:RadioButtons>
<muxc:RadioButtons.Resources>
<Style x:Key="DefaultRadioButtonStyle" TargetType="RadioButton">
<!---->
</Style>
</muxc:RadioButtons.Resources>
<Button Content="OptionButton1"/>
<Button Content="OptionButton2"/>
</muxc:RadioButtons> so you overwrite the default RadioButton style in use. Unfortunately, that does not appear to work. Also, I think adding a RadioButton icon by default is the correct step here, as we are in a I agree with you though that the RadioButton itself should be stylable. I would expect that to work just like I would normally style a RadioButton (by specifying a new RadioButton style), just that here we overwrite the existing default RadioButton style. |
I definitely see there is an issue here, but we don't want to make it useless for those that need to change the radio button style too :)
I couldn't agree more!
I agree with your thinking overall, we just have to figure out how to support styling the radio button itself too separate from the item content if needed. Changing the DefaultRadioButtonStyle across the board should be supported -- but it should be possible to do this on a per-control basis as well. (Actually, UWP needs implicit styles and to also define keys for all system default styles... separate issue). Adding a new property for the style of the RadioButton itself might work. We also have to consider right-to-left text layouts where the RadioButton should probably be on the right-hand side. |
Would the below pattern work ? That way you can set the properties on the RadioButton directly and don't need a Style.
|
@ranjeshj That works as expected (only adjusted some Margins for better design): The question is: Is this just a workaround? Or Is this how the ItemTemplate has to be constructed (RadioButton at the root)? In other words, do developers have to explictily specify a root RadioButton in the ItemTemplate? If so, how should we handle an ItemTemplate which lack a RadioButton as its root element? |
I see. If the RadioButton containers are automatically created by RadioButtons control, then there is no easy way to style that without exposing a Style/StyleSelector. |
A DataTemplate that requires a RadioButton as the root element actually makes sense to me in this case. It is a RadioButtons control after all. Technically speaking, are there actually any limitations with @ranjeshj solution? It seems to me it works in all cases. If you aren't using a RadioButton in the style then another repeater control should be used. We should just add a note in the documentation for this. |
@robloo @ranjeshj How about this: If we don't specify a However, if more styling flexibility for the RadioButton itself is required, I can specify a (The TreeView control for example does something like this with its ItemTemplate - if no TreeViewItem is specified, the ItemTemplate is wrapped into a TreeViewItem.) |
@robloo Do you think we should also add an ItemTemplateSelector API to the RadioButtons control? That API is missing so far and would give even more fine granular styling possibilities. Plus, it would help bring the same level of customization options to the RadioButtons control as known from other such Item controls. |
It wouldn't hurt. However, I'm not sure it's really justified. The RadioButons is not a general-purpose control. I can't really envision scenarios where we would need to change the template... Except maybe for when an item is checked. |
@robloo Yeah, I do not recall And yes, we should consider adding documentation how to customize the actual RadioButtons for the |
Sorry missed the ping.. I'm also thinking there likely isn't much to do here. If the root of the template is not a RadioButton, we could create one automatically for you which will fix this. The issue is that if RadioButtons automatically created a RadioButton for you, there is no explicit property to style that RadioButton. You could add a style to RadioButtons.ResourceDictionary. Alternatively you could provide your own RadioButton in the template and update its properties directly. This part probably just needs better documentation. |
@ranjeshj So, to summarize: What is to do here is to
I would like to work on both of these items. |
Describe the bug
According to #333 (comment) by @kikisaints, a custom ItemTemplate for the
RadioButtons
control will be prefaced by a RadioButton icon:Thus, if we have the following XAML:
and code-behind like this:
The expected UI is this:
![image](https://user-images.githubusercontent.com/1398851/90634864-ae5b2700-e228-11ea-92ce-a539216626e4.png)
But the actual UI we get is this:
![image](https://user-images.githubusercontent.com/1398851/90634900-c2068d80-e228-11ea-88d5-5de68ac2659e.png)
As you can see, there are no RadioButton icons, plus our items are no longer represented as
RadioButton
s internally, thus we cannot select our options in a mutually exclusive way (actually, we cannot select them at all).Version Info
NuGet package version:
Newest WinUI 2.5 preview.
Additional context
I would like to fix this.
The text was updated successfully, but these errors were encountered: