Native type is not registered error when calling FindName("myName") as ResourceDictionary
Posted: 14 Aug 2020, 15:19
I've got a big collection of flags that are stored in a <ResourceDictionary x:Name="myName"> in xaml. I wrote an IValueConverter that takes an input string from an item property in a collection and returns the svg resource. The code behind for the xaml exposes a ResouceDictionary property that I use in the IValueConverter to reference the dictionary and return values by key.
This is all working great in WPF, but in Unity when I call FindName("myName") to manually assign the ResourceDictionary to the accessor property, it throws an exception "System.InvalidOperationException: Native type is not registered". What am I doing wrong? Am I missing something?
Or, more generally, is there a better approach to displaying svg flags or icons or whatever than storing them as keyed resources in xaml?
Help! :)
for reference, here's some of my code:
The wrapper xaml
The code-behind
And finally my accessor in the IValueConverter:
This is all working great in WPF, but in Unity when I call FindName("myName") to manually assign the ResourceDictionary to the accessor property, it throws an exception "System.InvalidOperationException: Native type is not registered". What am I doing wrong? Am I missing something?
Or, more generally, is there a better approach to displaying svg flags or icons or whatever than storing them as keyed resources in xaml?
Help! :)
for reference, here's some of my code:
The wrapper xaml
Code: Select all
<UserControl x:Class="MyNamespace.FlagsWrapper"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:local="clr-namespace:MyNamespace"
mc:Ignorable="d"
d:DesignHeight="450" d:DesignWidth="800">
<UserControl.Resources>
<ResourceDictionary x:Name="FlagsResource"> Source="Styles/FlagsCollection.xaml"/>
</UserControl.Resources>
</UserControl>
Code: Select all
public partial class FlagsWrapper : UserControl
{
public ResourceDictionary FlagsDictionary { get; set; }
public FlagsWrapper()
{
InitializeComponent();
#if !NOESIS
FlagsDictionary = FlagsResource;
#endif
}
#if NOESIS
private void InitializeComponent()
{
Noesis.GUI.LoadComponent(this, "Assets/WPF/FlagsWrapper.xaml");
FlagsDictionary = FindName("FlagsResource") as ResourceDictionary;
}
#endif
}
Code: Select all
private ResourceDictionary m_flags;
public ResourceDictionary Flags
{
get
{
if (m_flags == null)
m_flags = new FlagsWrapper().FlagsDictionary;
return m_flags;
}
}