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

[Enhancement] Automatically importing specific resources #11798

@mattleibow

Description

@mattleibow

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.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions