|
2 | 2 |
|
3 | 3 | public static partial class ResourceDictionaryExtension |
4 | 4 | { |
5 | | - public static ResourceDictionary AddResource(this ResourceDictionary dic, string key, object value) |
| 5 | + public static T AddResource<T>(this T self, string key, object value) where T : Microsoft.Maui.Controls.ResourceDictionary |
6 | 6 | { |
7 | | - dic.Add(key, value); |
| 7 | + self.Add(key, value); |
8 | 8 |
|
9 | | - return dic; |
| 9 | + return self; |
10 | 10 | } |
11 | 11 |
|
12 | | - public static ResourceDictionary RemoveResource(this ResourceDictionary dic, string key) |
| 12 | + public static T AddResource<T>(this T self, Style style) where T : Microsoft.Maui.Controls.ResourceDictionary |
13 | 13 | { |
14 | | - dic.Remove(key); |
| 14 | + self.Add(style); |
15 | 15 |
|
16 | | - return dic; |
| 16 | + return self; |
| 17 | + } |
| 18 | + |
| 19 | + public static T AddResource<T>(this T self, Microsoft.Maui.Controls.StyleSheets.StyleSheet styleSheet) where T : Microsoft.Maui.Controls.ResourceDictionary |
| 20 | + { |
| 21 | + self.Add(styleSheet); |
| 22 | + |
| 23 | + return self; |
| 24 | + } |
| 25 | + |
| 26 | + public static T AddResource<T>(this T self, string strStyleSheet) where T : Microsoft.Maui.Controls.ResourceDictionary |
| 27 | + { |
| 28 | + self.Add(Microsoft.Maui.Controls.StyleSheets.StyleSheet.FromReader(new StringReader(strStyleSheet))); |
| 29 | + |
| 30 | + return self; |
| 31 | + } |
| 32 | + |
| 33 | + public static T AddResource<T>(this T self, ResourceDictionary mergedResourceDictionary) where T : Microsoft.Maui.Controls.ResourceDictionary |
| 34 | + { |
| 35 | + self.Add(mergedResourceDictionary); |
| 36 | + |
| 37 | + return self; |
| 38 | + } |
| 39 | + |
| 40 | + public static T RemoveResource<T>(this T self, string key) where T : Microsoft.Maui.Controls.ResourceDictionary |
| 41 | + { |
| 42 | + self.Remove(key); |
| 43 | + |
| 44 | + return self; |
| 45 | + } |
| 46 | + |
| 47 | + public static T MergedResources<T>(this T self, params ResourceDictionary[] resources) where T : Microsoft.Maui.Controls.ResourceDictionary |
| 48 | + { |
| 49 | + foreach (var resource in resources) |
| 50 | + { |
| 51 | + self.MergedDictionaries.Add(resource); |
| 52 | + } |
| 53 | + return self; |
| 54 | + } |
| 55 | + |
| 56 | + public static T MergedResources<T>(this T self, IList<ResourceDictionary> resources) where T : Microsoft.Maui.Controls.ResourceDictionary |
| 57 | + { |
| 58 | + foreach (var resource in resources) |
| 59 | + { |
| 60 | + self.MergedDictionaries.Add(resource); |
| 61 | + } |
| 62 | + return self; |
| 63 | + } |
| 64 | + |
| 65 | + public static T Source<T>(this T self, Uri uri) where T : Microsoft.Maui.Controls.ResourceDictionary |
| 66 | + { |
| 67 | + self.Source = uri; |
| 68 | + return self; |
| 69 | + } |
| 70 | + |
| 71 | + public static T Source<T>(this T self, string url) where T : Microsoft.Maui.Controls.ResourceDictionary |
| 72 | + { |
| 73 | + self.Source = new Uri(url); |
| 74 | + return self; |
17 | 75 | } |
18 | 76 | } |
0 commit comments