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

[Enhancement] Automatically importing specific resources #13766

Closed
mattleibow opened this issue Mar 8, 2023 · 1 comment
Closed

[Enhancement] Automatically importing specific resources #13766

mattleibow opened this issue Mar 8, 2023 · 1 comment
Labels
area-xaml XAML, CSS, Triggers, Behaviors proposal/open

Comments

@mattleibow
Copy link
Member

Summary

When creating a library, there does not appear to be a way to automagically import the required styles and templates.

API Changes

Not sure what the best way to do this as I can't think of all possible issues this may cause, however if we follow the UWP and WPF pattern, they have a special path in the library: Themes\Generic.xaml which is automatically imported. There are also a few other theme names, but they seem to be for specific styles of Windows.

See more: https://docs.microsoft.com/en-us/dotnet/framework/wpf/controls/control-authoring-overview

Intended Use Case

My particular use case is that I want to create a templated control and include a default set of styles for this new control in the library.

Current Implementations

There are currently 2 ways to get the same sort of operation now.

User

The first is on the user to import the dictionary in App.xaml:

<Application .. xmlns:themes="clr-namespace:SkiaSharp.Extended.Controls.Themes;assembly=SkiaSharp.Extended.Controls" x:Class="SkiaSharpDemo.App">
    <Application.Resources>
        <ResourceDictionary>
            <ResourceDictionary.MergedDictionaries>
                <themes:Generic />
            </ResourceDictionary.MergedDictionaries>
        </ResourceDictionary>
    </Application.Resources>
</Application>

This is "nice" but everyone will forget to do it.

Library

The other way which is "automatic" is done via the control constructor:

public class NewControl : TemplatedView
{
	public NewControl()
	{
		var merged = Application.Current?.Resources?.MergedDictionaries;
		if (merged != null)
		{
			var found = false;
			foreach (var dic in merged)
			{
				if (dic.GetType() == typeof(Themes.Generic))
				{
					found = true;
					break;
				}
			}
			if (!found)
				merged.Add(new Themes.Generic());
		}
	}

This is good in most cases, but obviously is not the greatest thing. The framework should do this all for me.

@mattleibow
Copy link
Member Author

Duplicate of #9612

@mattleibow mattleibow marked this as a duplicate of #9612 Mar 8, 2023
@Eilon Eilon added the area-xaml XAML, CSS, Triggers, Behaviors label Mar 8, 2023
@ghost ghost locked as resolved and limited conversation to collaborators Apr 7, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
area-xaml XAML, CSS, Triggers, Behaviors proposal/open
Projects
None yet
Development

No branches or pull requests

2 participants