如何解决单独程序集中的 ResourceDictionary 不起作用错误 无效的 URI
如果我尝试从类库中调用我的 ResourceDictionary,我会收到此错误。我遵循这个 Post 但它对我不起作用。我不知道我做错了什么。
无效的 URI:指定的端口无效。
我的 App.xaml:
<Application xmlns="http://xamarin.com/schemas/2014/forms"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
x:Class="JoinApp.App">
<Application.Resources>
<ResourceDictionary Source="pack://application:,/App_Libary;component/9.Resource/test.xaml"/>
</Application.Resources>
</Application>
我的 XAML:
<ContentPage xmlns="http://xamarin.com/schemas/2014/forms"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
NavigationPage.HasNavigationBar="false"
ControlTemplate="{StaticResource BaseTemplate}"
x:Class="App_Libary.Profile_Page">
<ContentView ControlTemplate="{StaticResource testcontrol}"/>
</ContentPage>
我的资源字典:
<ResourceDictionary xmlns="http://xamarin.com/schemas/2014/forms"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
x:Class="App_Libary._9.Resource.test">
<ControlTemplate x:Key="testcontrol">
<Label Text="this is a test"/>
</ControlTemplate>
</ResourceDictionary>
解决方法
你可以这样做:
创建ResourceDictionary
xaml(删除根属性中的x:Class
),例如名为mytemp.xaml
:
<ResourceDictionary xmlns="http://xamarin.com/schemas/2014/forms"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
>
<ControlTemplate x:Key="testcontrol">
<Label Text="this is a test"/>
</ControlTemplate>
</ResourceDictionary>
在您的 App.xaml
中定义:
i get this error if i try to inovke my ResourceDictionary from a Class Libary. I follow this Post but its dont works for me. I dont know what i do wrong.
无效的 URI:指定的端口无效。
我的 App.xaml:
<Application xmlns="http://xamarin.com/schemas/2014/forms"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
x:Class="JoinApp.App">
<Application.Resources>
<ResourceDictionary Source="mytemp.xaml"/> // if you have sub folder could use Source="yourfolder/mytemp.xaml"
</Application.Resources>
</Application>
然后在您的 page.xaml 中使用:
<ContentPage xmlns="http://xamarin.com/schemas/2014/forms"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
NavigationPage.HasNavigationBar="false"
ControlTemplate="{StaticResource BaseTemplate}"
x:Class="App_Libary.Profile_Page">
<ContentView ControlTemplate="{StaticResource testcontrol}"/>
</ContentPage>
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。