Skip to content
This repository has been archived by the owner on May 1, 2024. It is now read-only.

[Bug] How to get intellisense to work for resources from another assembly? #15140

Open
michaldivis opened this issue Feb 10, 2022 · 0 comments
Open

Comments

@michaldivis
Copy link

Description

This is more of a question than a bug report, I'm sorry if this isn't the right place to post it.

I wanted to separate my Xamarin app styling to a separate class library so it can be reused in other apps (light and dark theme, control styles, etc). However, the issue I'm running into is that when the class library is installed (via private nuget feed) and used in Xamarin apps, the Intellisense doesn't work for any of the color resources (it works for styles).

Is there a way to fix this? How can I tell my class library that the ResourceDictionaries it contains need to be present at design time for Intellisense to work?

Steps to Reproduce

The class library containing the resources

MyMobileThemes.csproj

<Project Sdk="Microsoft.NET.Sdk">

    <PropertyGroup>
        <TargetFrameworks>netstandard2.0;netstandard2.1</TargetFrameworks>
    </PropertyGroup>

    <ItemGroup>
        <PackageReference Include="Xamarin.Forms" Version="5.0.0.2337" />
    </ItemGroup>

    <ItemGroup>
        <EmbeddedResource Update="ControlStyles.xaml">
            <Generator>MSBuild:Compile</Generator>
        </EmbeddedResource>
        <EmbeddedResource Update="DarkTheme.xaml">
            <Generator>MSBuild:Compile</Generator>
        </EmbeddedResource>
        <EmbeddedResource Update="LightTheme.xaml">
            <Generator>MSBuild:Compile</Generator>
        </EmbeddedResource>
    </ItemGroup>

</Project>

LightTheme.xaml

<?xml version="1.0" encoding="utf-8" ?>
<ResourceDictionary
    x:Class="MyMobileThemes.LightTheme"
    xmlns="http://xamarin.com/schemas/2014/forms"
    xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml">

    <Color x:Key="cButtonBackground">#c5c7c4</Color>
    <Color x:Key="cButtonText">#000</Color>

    <Color x:Key="cSecondaryButtonBackground">#303030</Color>
    <Color x:Key="cSecondaryButtonText">#ffffff</Color>

    <Color x:Key="cDisabledButtonBackground">#ddd</Color>
    <Color x:Key="cDisabledButtonText">#888</Color>
    <Color x:Key="cPressedButtonBackground">#ddd</Color>
    <Color x:Key="cPressedButtonText">#000</Color>

    <!-- Other colors go here -->

</ResourceDictionary>

LightTheme.xaml.cs

using Xamarin.Forms;
using Xamarin.Forms.Xaml;

namespace MyMobileThemes
{
    [XamlCompilation(XamlCompilationOptions.Compile)]
    public partial class LightTheme : ResourceDictionary
    {
        public LightTheme()
        {
            InitializeComponent();
        }
    }
}

ControlStyles.xaml

<?xml version="1.0" encoding="utf-8" ?>
<ResourceDictionary
    x:Class="MyMobileThemes.ControlStyles"
    xmlns="http://xamarin.com/schemas/2014/forms"
    xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml">

    <!--  controls / button  -->
    <Style x:Key="MyButton" TargetType="Button">
        <Setter Property="TextColor" Value="{DynamicResource cButtonText}" />
        <Setter Property="BackgroundColor" Value="{DynamicResource cButtonBackground}" />
    </Style>
    <Style BasedOn="{StaticResource MyButton}" TargetType="Button" />

</ResourceDictionary>

ControlStyles.xaml.cs

using Xamarin.Forms;
using Xamarin.Forms.Xaml;

namespace MyMobileThemes
{
    [XamlCompilation(XamlCompilationOptions.Compile)]
    public partial class ControlStyles : ResourceDictionary
    {
        public ControlStyles()
        {
            InitializeComponent();
        }
    }
}

Consuming the library in Xamarin apps

SampleApp.csproj

<Project Sdk="Microsoft.NET.Sdk">

  <PropertyGroup>
    <TargetFramework>netstandard2.0</TargetFramework>
    <ProduceReferenceAssembly>true</ProduceReferenceAssembly>
  </PropertyGroup>

  <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|AnyCPU'">
    <DebugType>portable</DebugType>
    <DebugSymbols>true</DebugSymbols>
  </PropertyGroup>

  <ItemGroup>
    <PackageReference Include="MyCompany.MyMobileThemes" Version="1.9.1" />
    <PackageReference Include="Xamarin.Forms" Version="5.0.0.2337" />
    <PackageReference Include="Xamarin.Essentials" Version="1.7.1" />
  </ItemGroup>
</Project>

App.xaml

<?xml version="1.0" encoding="utf-8" ?>
<Application
    x:Class="SampleApp.App"
    xmlns="http://xamarin.com/schemas/2014/forms"
    xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
    xmlns:myMobileThemes="clr-namespace:MyMobileThemes;assembly=MyMobileThemes">
    <Application.Resources>

        <ResourceDictionary>
            <ResourceDictionary.MergedDictionaries>
                <myMobileThemes:LightTheme />
                <myMobileThemes:ControlStyles />
            </ResourceDictionary.MergedDictionaries>
        </ResourceDictionary>

    </Application.Resources>
</Application>

Expected Behavior

Intellisense works for all the resources when using the library in another Xamarin.Forms app.

Actual Behavior

Intellisense only works for styles, but not for any of the colors.

Intellisense works for this:

<Button Style="{StaticResource MyButton}" Text="Button" >

Intellisense doesn't work for this

<Button TextColor="{DynamicResource cButtonText}" Text="Button" >

Basic Information

  • Version with issue: 5.0.0.2337
  • Last known good version: ?
  • Platform Target Frameworks:
    • iOS: 15.2
    • Android: 10.0
  • NuGet Packages: none
  • Affected Devices: ?

Environment

Show/Hide Visual Studio info
Microsoft Visual Studio Professional 2022
Version 17.0.5
VisualStudio.17.Release/17.0.5+32112.339
Microsoft .NET Framework
Version 4.8.04084

Installed Version: Professional

Visual C++ 2022   00476-80000-00000-AA342
Microsoft Visual C++ 2022

.NET Core Debugging with WSL   1.0
.NET Core Debugging with WSL

ASP.NET and Web Tools 2019   17.0.795.42246
ASP.NET and Web Tools 2019

ASP.NET Web Frameworks and Tools 2019   17.0.795.42246
For additional information, visit https://www.asp.net/

Azure App Service Tools v3.0.0   17.0.795.42246
Azure App Service Tools v3.0.0

Azure Functions and Web Jobs Tools   17.0.795.42246
Azure Functions and Web Jobs Tools

C# Tools   4.0.1-1.21568.1+6ab6601178d9fba8c680b56934cd1742e0816bff
C# components used in the IDE. Depending on your project type and settings, a different version of the compiler may be used.

Common Azure Tools   1.10
Provides common services for use by Azure Mobile Services and Microsoft Azure Tools.

Extensibility Message Bus   1.2.6 (master@34d6af2)
Provides common messaging-based MEF services for loosely coupled Visual Studio extension components communication and integration.

Microsoft JVM Debugger   1.0
Provides support for connecting the Visual Studio debugger to JDWP compatible Java Virtual Machines

Microsoft Library Manager   2.1.134+45632ee938.RR
Install client-side libraries easily to any web project

Microsoft MI-Based Debugger   1.0
Provides support for connecting Visual Studio to MI compatible debuggers

Microsoft Visual C++ Wizards   1.0
Microsoft Visual C++ Wizards

Microsoft Visual Studio Tools for Containers   1.2
Develop, run, validate your ASP.NET Core applications in the target environment. F5 your application directly into a container with debugging, or CTRL + F5 to edit & refresh your app without having to rebuild the container.

Microsoft Visual Studio VC Package   1.0
Microsoft Visual Studio VC Package

Mono Debugging for Visual Studio   17.0.11 (54f19d2)
Support for debugging Mono processes with Visual Studio.

NuGet Package Manager   6.0.1
NuGet Package Manager in Visual Studio. For more information about NuGet, visit https://docs.nuget.org/

ProjectServicesPackage Extension   1.0
ProjectServicesPackage Visual Studio Extension Detailed Info

Razor (ASP.NET Core)   17.0.0.2156603+e9cd763349a080127b6519ffbec0123949a4c385
Provides languages services for ASP.NET Core Razor.

SQL Server Data Tools   17.0.62110.20190
Microsoft SQL Server Data Tools

StylerPackage Extension   1.0
StylerPackage Visual Stuido Extension Detailed Info

TypeScript Tools   17.0.1001.2002
TypeScript Tools for Microsoft Visual Studio

Visual Basic Tools   4.0.1-1.21568.1+6ab6601178d9fba8c680b56934cd1742e0816bff
Visual Basic components used in the IDE. Depending on your project type and settings, a different version of the compiler may be used.

Visual F# Tools   17.0.0-beta.21522.2+6d626ff0752a77d339f609b4d361787dc9ca93a5
Microsoft Visual F# Tools

Visual Studio Code Debug Adapter Host Package   1.0
Interop layer for hosting Visual Studio Code debug adapters in Visual Studio

Visual Studio Container Tools Extensions   1.0
View, manage, and diagnose containers within Visual Studio.

Visual Studio IntelliCode   2.2
AI-assisted development for Visual Studio.

Visual Studio Tools for Containers   1.0
Visual Studio Tools for Containers

VisualStudio.DeviceLog   1.0
Information about my package

VisualStudio.Foo   1.0
Information about my package

VisualStudio.Mac   1.0
Mac Extension for Visual Studio

WiX Toolset Visual Studio Extension   1.0.0.18
WiX Toolset Visual Studio Extension version 1.0.0.18
Copyright (c) .NET Foundation and contributors. All rights reserved.

Xamarin   17.0.0.343 (d17-0@fb07a17)
Visual Studio extension to enable development for Xamarin.iOS and Xamarin.Android.

Xamarin Designer   17.0.0.183 (remotes/origin/d17-0@a351f0f1f)
Visual Studio extension to enable Xamarin Designer tools in Visual Studio.

Xamarin Templates   17.0.17 (9e779b0)
Templates for building iOS, Android, and Windows apps with Xamarin and Xamarin.Forms.

Xamarin.Android SDK   12.1.0.5 (d17-0/6b0e6b2)
Xamarin.Android Reference Assemblies and MSBuild support.
    Mono: c633fe9
    Java.Interop: xamarin/java.interop/d17-0@febb1367
    ProGuard: Guardsquare/proguard/v7.0.1@912d149
    SQLite: xamarin/sqlite/3.36.0@a575761
    Xamarin.Android Tools: xamarin/xamarin-android-tools/d17-0@a5194e9


Xamarin.iOS and Xamarin.Mac SDK   15.4.0.0 (8fc41ae82)
Xamarin.iOS and Xamarin.Mac Reference Assemblies and MSBuild support.
@michaldivis michaldivis added s/unverified New report that has yet to be verified t/bug 🐛 labels Feb 10, 2022
@jfversluis jfversluis added t/question and removed t/bug 🐛 s/unverified New report that has yet to be verified labels Feb 11, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

2 participants