Setting styles in templated control causes control to crash under windows #2316
-
Create a simple control and try to set its style to some default style: internal class MyControl : Control
{
public MyControl()
{
DefaultStyleKey = typeof(MyControl);
Style = _defaultStyle; // crashes with COMException
}
} This causes exception: the app crashes only under net8.0-windows10.0.19041 to reproduce:
Alternatively take this one to reproduce: UnoNoInstalledComponentsApp.zip Tested only with windows: |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment
-
@kucint Apparently there is some limitiation in WinUI that requires controls to have default styles defined. To do so, you can create a XAML resource dictionary like: <ResourceDictionary
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:my="using:UnoAppTemplateBindingNotWorking.Controls">
<Style TargetType="my:MyControl" />
</ResourceDictionary> And then reference that dictionary in <Application
x:Class="UnoAppTemplateBindingNotWorking.App"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
<Application.Resources>
<ResourceDictionary>
<ResourceDictionary.MergedDictionaries>
<ResourceDictionary Source="ms-appx:///MyDictionary.xaml" />
</ResourceDictionary.MergedDictionaries>
</ResourceDictionary>
</Application.Resources>
</Application> |
Beta Was this translation helpful? Give feedback.
@kucint Apparently there is some limitiation in WinUI that requires controls to have default styles defined. To do so, you can create a XAML resource dictionary like:
And then reference that dictionary in
App.xaml
: