MaterialDesignInXAML / MaterialDesignInXAML/MaterialDesignInXamlToolkit
Use ComponentResourceKey instead of strings to identify resources
Dieses Issue hat noch niemand übernommen.
- Vorherrschende Sprache
- C#
- Sterne
- 16.3k
- Forks
- 3.5k
- Ø Merge
- 1 T. 22 Std.
- Gemergte PRs (30 T.)
- 8
Beschreibung
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
ComponentResourceKeywould 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:
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:
<Color Key="{x:Static md:MaterialDesignColors.Primary50Color}" ... />
When using the resource, we can now use a static reference that is checked by the compiler:
<Brush Color="{DynamicResource {x:Static md:MaterialDesignColors.Primary50Color}}" ... />
Beitragsleitfaden
Erste Schritte
- Lies das ganze Issue und danach den Beitragsleitfaden des Projekts.
- Schreib ins Issue, dass du es übernimmst — das erspart doppelte Arbeit.
- Forke das Repository und arbeite in einem Branch.
- Öffne einen Pull Request, der die Issue-Nummer nennt.
Rechercherichtung
Beginne damit, die Deklarationen der Ressourcenwörterbücher und die XAML-Verwendungen zu lokalisieren, die Ressourcen derzeit anhand von Zeichenfolgen identifizieren. Prüfe das vorgeschlagene statische ComponentResourceKey-Muster und bestimme den Umfang der Migration. Als abgeschlossen gilt die Arbeit, wenn Ressourcen compilergeprüfte Schlüssel verwenden und die Entscheidung zur Abwärtskompatibilität oder Versionierung dokumentiert und validiert ist.
Vom Indexierungsmodell aus dem Issue-Text verfasst.
Bewertung
- Tech-Stack
- csharp
- Bereich
- desktop
- Issue-Typ
- Feature
- Schwierigkeit
- 5/5
- Geschätzter Aufwand
- Über eine Woche
- Aktivitätsstatus
- Ruhig
- Klarheit
- Größtenteils klar
- Anfängerfreundlichkeit
- 35/100