问题描述
如果我尝试从类库中调用我的 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>