11#nullable disable
22using System ;
33using System . Windows . Input ;
4+ using Microsoft . Maui . Controls . Internals ;
45using Microsoft . Maui . Graphics ;
56
67namespace Microsoft . Maui . Controls
78{
89 /// <include file="../../../docs/Microsoft.Maui.Controls/TextCell.xml" path="Type[@FullName='Microsoft.Maui.Controls.TextCell']/Docs/*" />
9- public class TextCell : Cell
10+ public class TextCell : Cell , ICommandElement
1011 {
1112 /// <summary>Bindable property for <see cref="Command"/>.</summary>
12- public static readonly BindableProperty CommandProperty = BindableProperty . Create ( nameof ( Command ) , typeof ( ICommand ) , typeof ( TextCell ) , default ( ICommand ) ,
13- propertyChanging : ( bindable , oldvalue , newvalue ) =>
14- {
15- var textCell = ( TextCell ) bindable ;
16- var oldcommand = ( ICommand ) oldvalue ;
17- if ( oldcommand != null )
18- oldcommand . CanExecuteChanged -= textCell . OnCommandCanExecuteChanged ;
19- } , propertyChanged : ( bindable , oldvalue , newvalue ) =>
20- {
21- var textCell = ( TextCell ) bindable ;
22- var newcommand = ( ICommand ) newvalue ;
23- if ( newcommand != null )
24- {
25- textCell . IsEnabled = newcommand . CanExecute ( textCell . CommandParameter ) ;
26- newcommand . CanExecuteChanged += textCell . OnCommandCanExecuteChanged ;
27- }
28- } ) ;
13+ public static readonly BindableProperty CommandProperty =
14+ BindableProperty . Create ( nameof ( Command ) , typeof ( ICommand ) , typeof ( TextCell ) ,
15+ propertyChanging : CommandElement . OnCommandChanging ,
16+ propertyChanged : CommandElement . OnCommandChanged ) ;
2917
3018 /// <summary>Bindable property for <see cref="CommandParameter"/>.</summary>
31- public static readonly BindableProperty CommandParameterProperty = BindableProperty . Create ( nameof ( CommandParameter ) , typeof ( object ) , typeof ( TextCell ) , default ( object ) ,
32- propertyChanged : ( bindable , oldvalue , newvalue ) =>
33- {
34- var textCell = ( TextCell ) bindable ;
35- if ( textCell . Command != null )
36- {
37- textCell . IsEnabled = textCell . Command . CanExecute ( newvalue ) ;
38- }
39- } ) ;
19+ public static readonly BindableProperty CommandParameterProperty =
20+ BindableProperty . Create ( nameof ( CommandParameter ) ,
21+ typeof ( object ) ,
22+ typeof ( TextCell ) ,
23+ null ,
24+ propertyChanged : CommandElement . OnCommandParameterChanged ) ;
4025
4126 /// <summary>Bindable property for <see cref="Text"/>.</summary>
4227 public static readonly BindableProperty TextProperty = BindableProperty . Create ( nameof ( Text ) , typeof ( string ) , typeof ( TextCell ) , default ( string ) ) ;
@@ -104,9 +89,14 @@ protected internal override void OnTapped()
10489 Command ? . Execute ( CommandParameter ) ;
10590 }
10691
107- void OnCommandCanExecuteChanged ( object sender , EventArgs eventArgs )
92+ void ICommandElement . CanExecuteChanged ( object sender , EventArgs eventArgs )
10893 {
94+ if ( Command is null )
95+ return ;
96+
10997 IsEnabled = Command . CanExecute ( CommandParameter ) ;
11098 }
99+
100+ WeakCommandSubscription ICommandElement . CleanupTracker { get ; set ; }
111101 }
112102}
0 commit comments