毛伊岛:无法在两个SDK式项目之间共享资源计算
我有两个SDK风格的MAUI项目,例如Project1和Project2。 Project2具有以下结构:
Project2.sln
|
- Resources
|
- Colors.xaml
Colors.XAML具有以下代码:
<?xml version="1.0" encoding="UTF-8" ?>
<?xaml-comp compile="true" ?>
<ResourceDictionary xmlns="http://schemas.microsoft.com/dotnet/2021/maui"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
x:Class="Project2.Resources.Colors">
<Color x:Key="TestColor">#512BD4</Color>
</ResourceDictionary>
目标是在Project1中使用testColor
,也许是在Project3,Project4等之后。只要标准的wpf-like xaml符号在毛ui中不起作用,我们必须必须将此文件包含如下:
project1/app.xaml:
<?xml version="1.0" encoding="utf-8" ?>
<Application xmlns="http://schemas.microsoft.com/dotnet/2021/maui"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
xmlns:resources="clr-namespace:Project2.Resources;assembly=Project2"
x:Class="Project1.App">
<Application.Resources>
<ResourceDictionary>
<ResourceDictionary.MergedDictionaries>
<resources:Colors />
</ResourceDictionary.MergedDictionaries>
</ResourceDictionary>
</Application.Resources>
</Application>
至少可以在没有错误的情况下进行编译,但这无效。当我尝试在某些视图之王中使用新的静态资源时,例如:
project1/mainwindow.xaml:
<Grid BackgroundColor="{StaticResource TestColor}" />
它会引发运行时错误microsoft.maui.controls.xaml.xaml.xamlparseexception:'位置xx:xx:xx。对于键testcolor'
和Intellisense找不到的静电素,对testColor So so so so so so so so n n n nisthersense没有任何线索。问题是:我需要如何在其他毛伊岛的其他项目中正确链接我的外部资源界面?
I have two SDK-style MAUI projects, let's say Project1 and Project2. Project2 has following structure:
Project2.sln
|
- Resources
|
- Colors.xaml
Colors.xaml has the following code:
<?xml version="1.0" encoding="UTF-8" ?>
<?xaml-comp compile="true" ?>
<ResourceDictionary xmlns="http://schemas.microsoft.com/dotnet/2021/maui"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
x:Class="Project2.Resources.Colors">
<Color x:Key="TestColor">#512BD4</Color>
</ResourceDictionary>
The goal is to use TestColor
in Project1, maybe later in Project3, Project4, and so on. As long as standard WPF-like XAML notation does not work in MAUI, we have to include this file as following:
Project1/App.xaml:
<?xml version="1.0" encoding="utf-8" ?>
<Application xmlns="http://schemas.microsoft.com/dotnet/2021/maui"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
xmlns:resources="clr-namespace:Project2.Resources;assembly=Project2"
x:Class="Project1.App">
<Application.Resources>
<ResourceDictionary>
<ResourceDictionary.MergedDictionaries>
<resources:Colors />
</ResourceDictionary.MergedDictionaries>
</ResourceDictionary>
</Application.Resources>
</Application>
This one at least can compile without errors, but that does not work. When i am trying to use new static resource in some king of view, like this:
Project1/MainWindow.xaml:
<Grid BackgroundColor="{StaticResource TestColor}" />
It throws a runtime error Microsoft.Maui.Controls.Xaml.XamlParseException: 'Position XX:XX. StaticResource not found for key TestColor'
and IntelliSense having no clue about TestColor so. The question is: how do i need to properly link my external ResourceDictionary in other projects using MAUI?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
解决方法:在应用程序启动期间,手动将DLL中的所有条目复制到
application.current.resources
。在共享
app.xaml.cs
中:todo:代码以获取DLL的ResourceCtionary。
我没有在MAUI中与DLL合作,因此不确定您此步骤所需的代码。
Workaround: During app startup, manually copy all the entries in the dll's resourcedictionary into
Application.Current.Resources
.In shared
App.xaml.cs
:TODO: Code to get dll's resourcedictionary.
I haven't worked with dll's in Maui, so not certain the code you need for this step.