1
- using CommunityToolkit . Mvvm . DependencyInjection ;
1
+ using CommunityToolkit . Maui . Markup ;
2
+ using CommunityToolkit . Mvvm . DependencyInjection ;
2
3
using SimpleWeather . Icons ;
3
4
using SimpleWeather . Preferences ;
4
5
using SimpleWeather . SkiaSharp ;
@@ -83,7 +84,7 @@ public double IconHeight
83
84
}
84
85
85
86
public static readonly BindableProperty IconHeightProperty =
86
- BindableProperty . Create ( nameof ( IconHeight ) , typeof ( double ) , typeof ( IconControl ) , double . NaN , propertyChanged : ( obj , _ , _ ) => ( obj as IconControl ) ? . UpdateWeatherIcon ( ) ) ;
87
+ BindableProperty . Create ( nameof ( IconHeight ) , typeof ( double ) , typeof ( IconControl ) , - 1d , propertyChanged : ( obj , _ , _ ) => ( obj as IconControl ) ? . UpdateWeatherIcon ( ) ) ;
87
88
88
89
public double IconWidth
89
90
{
@@ -92,9 +93,9 @@ public double IconWidth
92
93
}
93
94
94
95
public static readonly BindableProperty IconWidthProperty =
95
- BindableProperty . Create ( nameof ( IconWidth ) , typeof ( double ) , typeof ( IconControl ) , double . NaN , propertyChanged : ( obj , _ , _ ) => ( obj as IconControl ) ? . UpdateWeatherIcon ( ) ) ;
96
+ BindableProperty . Create ( nameof ( IconWidth ) , typeof ( double ) , typeof ( IconControl ) , - 1d , propertyChanged : ( obj , _ , _ ) => ( obj as IconControl ) ? . UpdateWeatherIcon ( ) ) ;
96
97
97
- private readonly SettingsManager SettingsManager = Ioc . Default . GetService < SettingsManager > ( ) ;
98
+ private readonly SettingsManager _settingsManager = Ioc . Default . GetService < SettingsManager > ( ) ;
98
99
99
100
public IconControl ( )
100
101
{
@@ -124,7 +125,7 @@ public async void UpdateWeatherIcon()
124
125
// Remove any animatable drawables
125
126
RemoveAnimatedDrawables ( ) ;
126
127
127
- var wip = SharedModule . Instance . WeatherIconsManager . GetIconProvider ( IconProvider ?? SettingsManager . IconProvider ) ;
128
+ var wip = SharedModule . Instance . WeatherIconsManager . GetIconProvider ( IconProvider ?? _settingsManager . IconProvider ) ;
128
129
129
130
if ( ForceBitmapIcon )
130
131
{
@@ -188,18 +189,8 @@ public async void UpdateWeatherIcon()
188
189
189
190
e . Surface . Flush ( true ) ;
190
191
} ;
191
- canvas . SetBinding ( HeightRequestProperty , new Binding ( )
192
- {
193
- Source = this ,
194
- Path = nameof ( IconHeight ) ,
195
- Mode = BindingMode . OneWay ,
196
- } ) ;
197
- canvas . SetBinding ( WidthRequestProperty , new Binding ( )
198
- {
199
- Source = this ,
200
- Path = nameof ( IconWidth ) ,
201
- Mode = BindingMode . OneWay ,
202
- } ) ;
192
+ canvas . Bind ( HeightRequestProperty , static src => src . IconHeight , mode : BindingMode . OneWay , source : this ) ;
193
+ canvas . Bind ( WidthRequestProperty , static src => src . IconWidth , mode : BindingMode . OneWay , source : this ) ;
203
194
iconElement = canvas ;
204
195
205
196
if ( drawable is SKLottieDrawable lottieDrawable )
@@ -244,18 +235,8 @@ public async void UpdateWeatherIcon()
244
235
245
236
e . Surface . Flush ( true ) ;
246
237
} ;
247
- canvas . SetBinding ( HeightRequestProperty , new Binding ( )
248
- {
249
- Source = this ,
250
- Path = nameof ( IconHeight ) ,
251
- Mode = BindingMode . OneWay ,
252
- } ) ;
253
- canvas . SetBinding ( WidthRequestProperty , new Binding ( )
254
- {
255
- Source = this ,
256
- Path = nameof ( IconWidth ) ,
257
- Mode = BindingMode . OneWay ,
258
- } ) ;
238
+ canvas . Bind ( HeightRequestProperty , static src => src . IconHeight , mode : BindingMode . OneWay , source : this ) ;
239
+ canvas . Bind ( WidthRequestProperty , static src => src . IconWidth , mode : BindingMode . OneWay , source : this ) ;
259
240
iconElement = canvas ;
260
241
}
261
242
catch ( Exception e )
@@ -276,7 +257,7 @@ public async void UpdateWeatherIcon()
276
257
277
258
private bool ShouldUseBitmap ( )
278
259
{
279
- return ShowAsMonochrome && IconColor != Colors . Transparent && ! IsBlackOrWhiteColor ( IconColor ) ;
260
+ return ShowAsMonochrome && ! Equals ( IconColor , Colors . Transparent ) && ! IsBlackOrWhiteColor ( IconColor ) ;
280
261
}
281
262
282
263
private bool IsBlackOrWhiteColor ( Color c )
@@ -315,18 +296,8 @@ private async Task<IView> CreateBitmapIcon(IWeatherIconsProvider provider)
315
296
316
297
e . Surface . Flush ( true ) ;
317
298
} ;
318
- canvas . SetBinding ( HeightRequestProperty , new Binding ( )
319
- {
320
- Source = this ,
321
- Path = nameof ( IconHeight ) ,
322
- Mode = BindingMode . OneWay ,
323
- } ) ;
324
- canvas . SetBinding ( WidthRequestProperty , new Binding ( )
325
- {
326
- Source = this ,
327
- Path = nameof ( IconWidth ) ,
328
- Mode = BindingMode . OneWay ,
329
- } ) ;
299
+ canvas . Bind ( HeightRequestProperty , static src => src . IconHeight , mode : BindingMode . OneWay , source : this ) ;
300
+ canvas . Bind ( WidthRequestProperty , static src => src . IconWidth , mode : BindingMode . OneWay , source : this ) ;
330
301
331
302
return canvas ;
332
303
}
0 commit comments