MaterialDesignInXAML / MaterialDesignInXAML/MaterialDesignInXamlToolkit
Use ComponentResourceKey instead of strings to identify resources
Nessuno ha ancora preso questa issue.
- Lingua principale
- C#
- Stelle
- 16.3k
- Fork
- 3.5k
- Merge medio
- 1g 22h
- PR unite (30g)
- 8
Descrizione
**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
```
Guida per i contributori
Apri la guida per i contributori
Come iniziare
- Leggi tutta la issue e poi la guida ai contributi del progetto.
- Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
- Fai un fork del repository e lavora su un branch.
- Apri una pull request che faccia riferimento al numero della issue.
Direzione di ricerca
Inizia individuando le dichiarazioni dei dizionari di risorse e gli utilizzi XAML che attualmente identificano le risorse tramite stringhe. Esamina il pattern statico ComponentResourceKey proposto e determina l'ambito della migrazione. Il lavoro è completato quando le risorse usano chiavi verificate dal compilatore e la decisione relativa alla compatibilità con le versioni precedenti o al versioning è documentata e convalidata.
Scritto dal modello di indicizzazione a partire dal testo della issue.
Valutazione
- Stack tecnologico
- csharp
- Ambito
- desktop
- Tipo di issue
- Funzionalità
- Difficoltà
- 5/5
- Tempo stimato
- Più di una settimana
- Stato di attività
- Tranquilla
- Chiarezza
- Abbastanza chiara
- Idoneità per principianti
- 35/100