Extracting styles to a .NET MAUI Class Library project does not compile

1 Answer 214 Views
TabView
Petra
Top achievements
Rank 1
Petra asked on 02 Jun 2022, 02:41 PM

Hi

I am trying to extract my styling for a Telerik TabView into a .NET MAUI Class Library project, which I include in my MAUI application project and reference the ResourceDictionary from there. However, when I try to run the app to Android, I get the following error:

Failed to resolve assembly: 'Telerik.Maui.Controls, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null'

I have even tried to do this for the SDKBrowserMaui example project that shipped with the Telerik installation. The steps I followed are:

1. Add a new project in the solution. Choose ".NET MAUI Class Library".

2. Add the Telerik nuget to this new project.

3. Create a folder named Resources in the new project and add a ".NET MAUI ResourceDictionary (XAML)" file to this folder. I called it "Styles.xaml".

4. Inside the xaml file, add an assembly reference as follows:

xmlns:telerik="clr-namespace:Telerik.Maui.Controls;assembly=Telerik.Maui.Controls"

(I saw this in the maui app project, inside App.xaml)

5. Add my styles to the ResourceDictionary as follows:


<?xml version="1.0" encoding="utf-8" ?>
<ResourceDictionary
	x:Class="MauiLib1.Resources.Styles"
	xmlns="http://schemas.microsoft.com/dotnet/2021/maui"
	xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
	xmlns:telerik="clr-namespace:Telerik.Maui.Controls;assembly=Telerik.Maui.Controls">

	<Style x:Key="tvhi" TargetType="telerik:TabViewHeaderItem">
		<Setter Property="Padding" Value="10,5" />
		<Setter Property="VisualStateManager.VisualStateGroups">
			<VisualStateGroupList>
				<VisualStateGroup Name="CommonStates">
					<VisualState Name="Normal">
						<VisualState.Setters>
							<Setter Property="TextColor" Value="#99ffffff" />
							<Setter Property="FontAttributes" Value="Bold" />
							<Setter Property="BackgroundColor" Value="Transparent" />
						</VisualState.Setters>
					</VisualState>
					<VisualState Name="Disabled">
						<VisualState.Setters>
							<Setter Property="TextColor" Value="#b3b3b3" />
							<Setter Property="FontAttributes" Value="Bold" />
							<Setter Property="BackgroundColor" Value="Transparent" />
						</VisualState.Setters>
					</VisualState>
					<VisualState Name="Selected">
						<VisualState.Setters>
							<Setter Property="TextColor" Value="White" />
							<Setter Property="FontAttributes" Value="Bold" />
							<Setter Property="BackgroundColor" Value="Transparent" />
						</VisualState.Setters>
					</VisualState>
				</VisualStateGroup>
			</VisualStateGroupList>
		</Setter>
	</Style>

	<Style x:Key="tvh" TargetType="telerik:TabViewHeader">
		<Setter Property="BackgroundColor" Value="Transparent" />
		<Setter Property="HorizontalOptions" Value="Start" />
	</Style>

	<Style x:Key="tvc" TargetType="telerik:TabViewContent">
		<Setter Property="VerticalOptions" Value="Fill" />
	</Style>

</ResourceDictionary>

6. Add a reference to the Class library project in the Maui project.

7. Inside the Maui app, in App.xaml, add the new ResourceDictionary.  I should now be able to add these keys as StaticResource in my code.

However when I compile, I get the following error:

Failed to resolve assembly: 'Telerik.Maui.Controls, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null' MauiLib1 C:\Program Files (x86)\Progress\Telerik UI for .NET MAUI 1.0.1\Examples\MauiLib1\Resources\Styles.xaml 1

Please can you assist, what am I doing wrong? I also tried to add the assembly reference as in my normal xaml files:

xmlns:telerik="http://schemas.telerik.com/2022/xaml/maui"

But this gives me the error:

Cannot resolve type "http://schemas.telerik.com/2022/xaml/maui:TabViewHeaderItem". MauiLib1 C:\Program Files (x86)\Progress\Telerik UI for .NET MAUI 1.0.1\Examples\MauiLib1\Resources\Styles.xaml 8

Thank you in advance for the support.


1 Answer, 1 is accepted

Sort by
1
Accepted
Antoan
Telerik team
answered on 06 Jun 2022, 10:10 AM

Hello Petra,

Everything seems correct in the steps below. .NET Maui Class Library project targets .net6.0, android, ios, windows, and macCatalyst.

Here is the .csproj file of the class library:

<TargetFrameworks>net6.0;net6.0-android;net6.0-ios;net6.0-maccatalyst</TargetFrameworks>

Telerik UI for .NET MAUI controls targets .net6.0-android/iOS/windows/maccatalyst. So remove the .net6.0 target framework from the csproj file. 

Example:

<TargetFrameworks>net6.0-android;net6.0-ios;net6.0-maccatalyst</TargetFrameworks>

I hope the provided information helps. Let me know if this works for you.

Regards,
Antoan
Progress Telerik

Virtual Classroom, the free self-paced technical training that gets you up to speed with Telerik and Kendo UI products quickly just got a fresh new look + new and improved content including a brand new Blazor course! Check it out at https://learn.telerik.com/.

Petra
Top achievements
Rank 1
commented on 07 Jun 2022, 01:49 PM

Hi Antoan

Thank you for the response. This does solve the problem although it introduces other problems when referencing the project from other projects that need to have the .net 6.0 target framework. I will see if we can work around this issue.

Thanks again!

Petra

Tags
TabView
Asked by
Petra
Top achievements
Rank 1
Answers by
Antoan
Telerik team
Share this question
or