MaterialDesignInXAML / MaterialDesignInXAML/MaterialDesignInXamlToolkit

Use ComponentResourceKey instead of strings to identify resources

Open
#3,918 1 comment 0 reactions 0 assignees View on GitHub
enhancement evaluation required
Dominant language
C#
Stars
16.3k
Forks
3.5k
Avg merge
1d 22h
Merged PRs (30d)
8

Description

**Is your feature request related to a problem? Please describe.**
- Currently resources are identified using strings. The string can only be validated at runtime and not while writing the XAML code
- When a resource key changes in a new version, the compiler does not indicate a problem and we get an Exception at runtime

**Describe the solution you'd like**
- Using `ComponentResourceKey` would make resources type-save
- **Optional**: preserve the existing string-based resource keys for backward-compatibility, or increase the version number because of breaking changes

**Describe alternatives you've considered**
- Don't know a better way

**Additional context**
To create the resource key, you need to create a Component resource key in a static class:
```csharp
public static partial class MaterialDesignColors
{
public static ComponentResourceKey Primary50Color { get; } = new(typeof(MaterialDesignColors), nameof(Primary50Color));
// ...
}
```

When declaring the resource in the `ResouceDictionary`, use the `ComponentResourceKey` as `Key`:
```xaml

```

When using the resource, we can now use a static reference that is checked by the compiler:
```xaml

```

Contributor guide

Open the contributing guide

Research direction

Start by locating the resource dictionary declarations and XAML usages that currently identify resources with strings. Review the proposed static ComponentResourceKey pattern and determine the scope of the migration. Done means resources use compiler-checked keys, with the backward-compatibility or versioning decision documented and validated.

Written by the indexing model from the issue text.

Assessment

Tech stack
csharp
Domain
desktop
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Quiet
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.