11#nullable enable
22using System ;
3- using System . Collections . Concurrent ;
43using System . Collections . Generic ;
54using System . Diagnostics ;
65using System . Diagnostics . CodeAnalysis ;
7- using System . Linq ;
8- using System . Reflection ;
9- using System . Threading . Tasks ;
106using Microsoft . UI . Xaml ;
117using Microsoft . UI . Xaml . Controls ;
128using Microsoft . UI . Xaml . Media ;
139using Windows . UI . ViewManagement ;
14- using WBinding = Microsoft . UI . Xaml . Data . Binding ;
15- using WBindingExpression = Microsoft . UI . Xaml . Data . BindingExpression ;
16- using WBrush = Microsoft . UI . Xaml . Media . Brush ;
1710using WPoint = Windows . Foundation . Point ;
1811
1912namespace Microsoft . Maui . Platform
2013{
2114 internal static class FrameworkElementExtensions
2215 {
23- static readonly Lazy < ConcurrentDictionary < Type , DependencyProperty > > ForegroundProperties =
24- new Lazy < ConcurrentDictionary < Type , DependencyProperty > > ( ( ) => new ConcurrentDictionary < Type , DependencyProperty > ( ) ) ;
25-
2616 public static T ? GetResource < T > ( this FrameworkElement element , string key , T ? def = default )
2717 {
2818 if ( element . Resources . TryGetValue ( key , out var resource ) )
@@ -31,59 +21,6 @@ internal static class FrameworkElementExtensions
3121 return def ;
3222 }
3323
34- public static WBrush GetForeground ( this FrameworkElement element )
35- {
36- if ( element == null )
37- throw new ArgumentNullException ( nameof ( element ) ) ;
38-
39- return ( WBrush ) element . GetValue ( GetForegroundProperty ( element ) ) ;
40- }
41-
42- public static WBinding ? GetForegroundBinding ( this FrameworkElement element )
43- {
44- WBindingExpression expr = element . GetBindingExpression ( GetForegroundProperty ( element ) ) ;
45-
46- if ( expr == null )
47- return null ;
48-
49- return expr . ParentBinding ;
50- }
51-
52- public static object GetForegroundCache ( this FrameworkElement element )
53- {
54- WBinding ? binding = GetForegroundBinding ( element ) ;
55-
56- if ( binding != null )
57- return binding ;
58-
59- return GetForeground ( element ) ;
60- }
61-
62- public static void RestoreForegroundCache ( this FrameworkElement element , object cache )
63- {
64- var binding = cache as WBinding ;
65- if ( binding != null )
66- SetForeground ( element , binding ) ;
67- else
68- SetForeground ( element , ( WBrush ) cache ) ;
69- }
70-
71- public static void SetForeground ( this FrameworkElement element , WBrush foregroundBrush )
72- {
73- if ( element == null )
74- throw new ArgumentNullException ( nameof ( element ) ) ;
75-
76- element . SetValue ( GetForegroundProperty ( element ) , foregroundBrush ) ;
77- }
78-
79- public static void SetForeground ( this FrameworkElement element , WBinding binding )
80- {
81- if ( element == null )
82- throw new ArgumentNullException ( nameof ( element ) ) ;
83-
84- element . SetBinding ( GetForegroundProperty ( element ) , binding ) ;
85- }
86-
8724 public static void UpdateVerticalTextAlignment ( this Control platformControl , ITextAlignment textAlignment )
8825 {
8926 platformControl . VerticalAlignment = textAlignment . VerticalTextAlignment . ToPlatformVerticalAlignment ( ) ;
@@ -168,29 +105,6 @@ internal static void TryUpdateResource(this FrameworkElement element, object new
168105 element ? . RefreshThemeResources ( ) ;
169106 }
170107
171- static DependencyProperty ? GetForegroundProperty ( FrameworkElement element )
172- {
173- if ( element is Control )
174- return Control . ForegroundProperty ;
175- if ( element is TextBlock )
176- return TextBlock . ForegroundProperty ;
177-
178- Type type = element . GetType ( ) ;
179-
180- if ( ! ForegroundProperties . Value . TryGetValue ( type , out var foregroundProperty ) )
181- {
182- if ( ReflectionExtensions . GetFields ( type ) . FirstOrDefault ( f => f . Name == "ForegroundProperty" ) is not FieldInfo field )
183- throw new ArgumentException ( "type is not a Foregroundable type" ) ;
184-
185- if ( field . GetValue ( null ) is DependencyProperty property )
186- ForegroundProperties . Value . TryAdd ( type , property ) ;
187-
188- return null ;
189- }
190-
191- return foregroundProperty ;
192- }
193-
194108 internal static IEnumerable < T ? > GetChildren < T > ( this DependencyObject parent ) where T : DependencyObject
195109 {
196110 int myChildrenCount = VisualTreeHelper . GetChildrenCount ( parent ) ;
0 commit comments