You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I have a project that intends to dynamically import ResourceDictionary, and I do this through code like this:
public static void AddResourceInclude(string path)
{
try
{
ResourceInclude _resourceInclude = new ResourceInclude(new Uri(path)) { Source = new Uri(path) };
if (Application.Current is { })
{
Application.Current.Resources.MergedDictionaries.Add(_resourceInclude);
}
}
catch (Exception ex)
{
}
}
In the case of non-AOT compilation, it runs everything fine
However, under AOT compilation, TRY&CATCH did not catch any errors, but all TemplatedControls of ResourceDictionary could not be displayed correctly.
However, if I load ResourceDictionary through App.XAML, everything works fine under AOT. The code is as follows:
<Application xmlns="https://github.com/avaloniaui"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
x:Class="WarWolf.App"
RequestedThemeVariant="Default">
<!-- "Default" ThemeVariant follows system theme variant. "Dark" or "Light" are other available options. -->
<Application.Styles>
<FluentTheme />
</Application.Styles>
<Application.Resources>
<ResourceDictionary>
<ResourceDictionary.MergedDictionaries>
<ResourceInclude Source="avares://GNSefer/Resources/Universal.axaml"></ResourceInclude>
</ResourceDictionary.MergedDictionaries>
</ResourceDictionary>
</Application.Resources>
</Application>
Therefore, I believe that the Source URI is fine, and the problem should be in the code that dynamically loads ResourceDictionary. How can I correctly dynamically load ResourceDictionary under AOT compilation?
I followed the method in your Additional context and added x:Class and an empty cs file with the same name as the XAML file to ResourceDictionary. The code is as follows:
But when I press CTRL+SHIFT+B to compile, VS prompts this error: Unable to resolve suitable regular or attached property MergedDictionaries on type Sample.Resources.Landscape Line 1, position 2.
How can I fix this error?
PS:NormalTextSplashScreenDialog and JumpingBallSplashScreenDialog above all are TemplatedControl with different ResourceDictionary in Landscape and Portrait.
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
-
I have a project that intends to dynamically import ResourceDictionary, and I do this through code like this:
In the case of non-AOT compilation, it runs everything fine
However, under AOT compilation, TRY&CATCH did not catch any errors, but all TemplatedControls of ResourceDictionary could not be displayed correctly.
However, if I load ResourceDictionary through App.XAML, everything works fine under AOT. The code is as follows:
Therefore, I believe that the Source URI is fine, and the problem should be in the code that dynamically loads ResourceDictionary. How can I correctly dynamically load ResourceDictionary under AOT compilation?
Beta Was this translation helpful? Give feedback.
All reactions