Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Generic.xaml defined in the project head is not taken into account #10327

Open
jeromelaban opened this issue Nov 3, 2022 · 3 comments
Open
Labels
difficulty/medium 🤔 Categorizes an issue for which the difficulty level is reachable with a good understanding of WinUI kind/bug Something isn't working project/styling 👔 Categorizes an issue or PR as relevant to element styling

Comments

@jeromelaban
Copy link
Member

Current behavior

Create a project with implicit styles defined in a Generic.xaml defined in the shared project of the heads. Use controls that use these styles.

Expected behavior

The controls are styled properly

How to reproduce it (as minimally and precisely as possible)

No response

Workaround

Create another resource dictionary, named Styles/Controls.xaml, then reference it from App.xaml:

<Application.Resources>
    <ResourceDictionary>
        <ResourceDictionary.MergedDictionaries>
            <XamlControlsResources xmlns="using:Microsoft.UI.Xaml.Controls" />
            <ResourceDictionary Source="Styles/Controls.xaml" />
        </ResourceDictionary.MergedDictionaries>

    </ResourceDictionary>
</Application.Resources>

Works on UWP/WinUI

Yes

Environment

No response

NuGet package version(s)

4.6.19

Affected platforms

No response

IDE

No response

IDE version

No response

Relevant plugins

No response

Anything else we need to know?

Related to #10276

@jeromelaban jeromelaban added kind/bug Something isn't working triage/untriaged Indicates an issue requires triaging or verification difficulty/tbd Categorizes an issue for which the difficulty level needs to be defined. project/styling 👔 Categorizes an issue or PR as relevant to element styling and removed triage/untriaged Indicates an issue requires triaging or verification labels Nov 3, 2022
@ToddGlodek
Copy link

@jeromelaban - the workaround seems just fine if you have the ' Source="Styles/Controls.xaml" ' in the .Shared project.

However, I'm not sure how this works if the ResourceDictionary containing the control layouts is defined in a Uno Platform Library. Will adding a second XamlControlsResources entry pointing to a namespace in MyProject work?

          <XamlControlsResources xmlns="using:Microsoft.UI.Xaml.Controls" />
          <XamlControlsResources xmlns="using:MyProject.Controls" />

Or, to I a have to add the in every project that consumes the non-shared cross platform library (but somehow referring to the referenced assembly).

@jeromelaban
Copy link
Member Author

<XamlControlsResources/> is specific to WinUI, you cannot reuse the type across.

Cross platform libraries support Generic.xaml (see here), it's only the head project that does not.

@MartinZikmund MartinZikmund changed the title Generic.xaml defined in the project head is not taken into account Generic.xaml defined in the project head is not taken into account Aug 16, 2023
@MartinZikmund MartinZikmund added difficulty/medium 🤔 Categorizes an issue for which the difficulty level is reachable with a good understanding of WinUI and removed difficulty/tbd Categorizes an issue for which the difficulty level needs to be defined. labels Aug 16, 2023
@mcNets
Copy link
Contributor

mcNets commented Sep 3, 2024

@jeromelaban I'm facing another error that I am not sure if it is related. Using an implicit style in a custom control defined in a controls library. The errors disappears if I add and use a Key.

This is the Generic.xaml file:

<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
					xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
					xmlns:local="using:UnoKeyboard.Controls">

	<Style TargetType="local:Keyboard">
		<Setter Property="Template">
			<Setter.Value>
				<ControlTemplate TargetType="local:Keyboard">
						<Border x:Name="PanelRoot"
								Width="{TemplateBinding Width}"
								Height="{TemplateBinding Height}"
								Background="{TemplateBinding Background}"
								BorderBrush="{TemplateBinding BorderBrush}"
								BorderThickness="{TemplateBinding BorderThickness}" />
				</ControlTemplate>
			</Setter.Value>
		</Setter>
	</Style>

	<Style TargetType="local:Keyboard">
		<Setter Property="Background"
				Value="{ThemeResource SystemControlBackgroundBaseLowBrush}" />
		<Setter Property="BorderThickness"
				Value="1" />
		<Setter Property="BorderBrush"
				Value="{ThemeResource SystemControlForegroundBaseMediumBrush}" />
	</Style>

</ResourceDictionary>

When I build the project that uses this control I'm getting that error several times:

1>CSC : error UXAML0001: Dictionary Item Style has duplicate key typeof(global::UnoKeyboard.Controls.Keyboard) .
1>CSC : error UXAML0001: Processing failed for file C:\Code\KeyboardControl\UnoKeyboard\Themes\Generic.xaml (System.InvalidOperationException: Dictionary Item Style has duplicate key typeof(global::UnoKeyboard.Controls.Keyboard) .
1>Done building project "UnoKeyboard.csproj" -- FAILED.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
difficulty/medium 🤔 Categorizes an issue for which the difficulty level is reachable with a good understanding of WinUI kind/bug Something isn't working project/styling 👔 Categorizes an issue or PR as relevant to element styling
Projects
None yet
Development

No branches or pull requests

4 participants