0

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.

Invalid URI: Invalid port specified.

My 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>

My 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>

My ResourceDictionary:

    <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>
JdDEV
  • 43
  • 5
  • Does this answer your question? [ResourceDictionary in a separate assembly](https://stackoverflow.com/questions/338056/resourcedictionary-in-a-separate-assembly) – Cfun Mar 13 '21 at 18:35
  • I try it but i get still the same error – JdDEV Mar 13 '21 at 19:15
  • Have you tried all answers, and important comments on that question? – Cfun Mar 13 '21 at 19:40
  • @LeoZhu-MSFTI haven't had time to test it yet, as soon as I find the time I'll answer here. – JdDEV Apr 03 '21 at 00:25

1 Answers1

0

You could do like below:

create the ResourceDictionary xaml (remove x:Class in the root attribute),for example named 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>

define in your 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.

Invalid URI: Invalid port specified.

My 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>

then use in your 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>
Leo Zhu
  • 15,726
  • 1
  • 7
  • 23