admin管理员组文章数量:1123271
I have a DLL which contains a custom Avalonia control and its default style and resources.
I can load the DLL dynamically like this and use the control without issue:
var basePath = Directory.GetCurrentDirectory();
var dll = Assembly.LoadFile(Path.Combine(basePath, "Components.dll"));
foreach (var type in dll.GetExportedTypes())
{
if (type.IsAssignableTo(typeof(IComponentPlugin)))
{
var instance = Activator.CreateInstance(type);
if (instance is IComponentPlugin plugin)
{
// Do Stuff
}
}
}
Now, i want to add the default style and resources to my Application
's, and it's somehow very hard.
I can retrieve a StyleInclude
and ResourceInclude
from my DLL, by putting this in IComponentPlugin
:
public ResourceInclude? GetResources()
{
var uri = new Uri("avares://DefaultResources.axaml");
return new ResourceInclude(uri) { Source = uri };
}
public StyleInclude? GetStyle()
{
var uri = new Uri("avares://DefaultStyle.axaml");
return new StyleInclude(uri) { Source = uri };
}
But, when i try to add it to my Application
's resources, AvaloniaXamlLoader
complains. "No precompiled XAML found for avares://DefaultResources.axaml/ (baseUri: avares://DefaultResources.axaml/)".
I tried instead getting the content of the file and loading it with AvaloniaRuntimeXamlLoader
from the Avalonia.Markup.Xaml.Loader
package:
public Stream? GetResources()
{
return AssetLoader.Open(new Uri("avares://DefaultResources.axaml"));
}
But then, i get a FileNotFoundException
"The resource avares://DefaultResources.axaml/ could not be found.". I also tried with "avares://Components/DefaultResources.axaml"
to no avail.
What would be the way to add the resources to my Application
?
版权声明:本文标题:avaloniaui - How do i get a ResourceDictionary from a xaml file in a dynamically loaded DLL - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1736559049a1944619.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论