microsoft / microsoft/microsoft-ui-xaml
Default control styles not found if it contains a `controls:` prefix in `Generic.xaml`
- Dominant language
- C++
- Stars
- 8.4k
- Forks
- 942
- Avg merge
- 2d 7h
- Merged PRs (30d)
- 105
Description
### Describe the bug
I am re-templating `RadioButtons` so I use `BasedOn="{StaticResource DefaultRadioButtonsStyle}"` to save some typing, but it does not find the resource.
### Why is this important?
This crash the app at runtime.
### Steps to reproduce the bug
1. Use this xaml
```xml
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="RadioButtons">
<StackPanel>
<ContentPresenter
x:Name="HeaderContentPresenter"
Margin="{ThemeResource RadioButtonsTopHeaderMargin}"
Content="{TemplateBinding Header}"
ContentTemplate="{TemplateBinding HeaderTemplate}"
Foreground="{ThemeResource RadioButtonsHeaderForeground}" />
<ItemsRepeater xmlns:primitives="using:Microsoft.UI.Xaml.Controls.Primitives" x:Name="InnerRepeater">
<ItemsRepeater.Layout>
<StackLayout Orientation="Horizontal" Spacing="{ThemeResource RadioButtonsRowSpacing}" />
</ItemsRepeater.Layout>
</ItemsRepeater>
<VisualStateManager.VisualStateGroups>
<VisualStateGroup x:Name="CommonStates">
<VisualState x:Name="Normal" />
<VisualState x:Name="Disabled">
<VisualState.Setters>
<Setter Target="HeaderContentPresenter.Foreground" Value="{ThemeResource RadioButtonsHeaderForegroundDisabled}" />
</VisualState.Setters>
</VisualState>
</VisualStateGroup>
</VisualStateManager.VisualStateGroups>
</StackPanel>
</ControlTemplate>
</Setter.Value>
</Setter>
```
### Actual behavior
Got an Exception: 'Cannot find a Resource with the Name/Key DefaultRadioButtonsStyle'.
Then crash
### Expected behavior
Find the resource.
### Screenshots
_No response_
### NuGet package version
WinUI 3 - Windows App SDK 1.8.3: 1.8.251106002
### Windows version
Windows 11 (24H2): Build 26100, Windows 10 (1809): Build 17763
### Additional context
The resource is actually defined in `generic.xaml`
```xml
<Setter Property="IsTabStop" Value="False" />
<Setter Property="TabNavigation" Value="Once" />
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="controls:RadioButtons">
<StackPanel>
<VisualStateManager.VisualStateGroups>
<VisualStateGroup x:Name="CommonStates">
<VisualState x:Name="Normal" />
<VisualState x:Name="Disabled">
<VisualState.Setters>
<Setter Target="HeaderContentPresenter.Foreground" Value="{ThemeResource RadioButtonsHeaderForegroundDisabled}" />
</VisualState.Setters>
</VisualState>
</VisualStateGroup>
</VisualStateManager.VisualStateGroups>
<ContentPresenter x:Name="HeaderContentPresenter" Content="{TemplateBinding Header}" ContentTemplate="{TemplateBinding HeaderTemplate}" Foreground="{ThemeResource RadioButtonsHeaderForeground}" Margin="{ThemeResource RadioButtonsTopHeaderMargin}" />
<controls:ItemsRepeater x:Name="InnerRepeater">
<controls:ItemsRepeater.Layout>
<primitives:ColumnMajorUniformToLargestGridLayout MaxColumns="{Binding RelativeSource={RelativeSource TemplatedParent}, Path=MaxColumns}" ColumnSpacing="{ThemeResource RadioButtonsColumnSpacing}" RowSpacing="{ThemeResource RadioButtonsRowSpacing}" />
</controls:ItemsRepeater.Layout>
</controls:ItemsRepeater>
</StackPanel>
</ControlTemplate>
</Setter.Value>
</Setter>
```
Contributor guide
Assessment
This issue has not been assessed yet.