@@ -5,123 +5,123 @@ namespace Maui.Controls.Sample;
55
66public class EditorControlPage : NavigationPage
77{
8- private EditorViewModel _viewModel ;
8+ private EditorViewModel _viewModel ;
99
10- public EditorControlPage ( )
11- {
12- _viewModel = new EditorViewModel ( ) ;
13- PushAsync ( new EditorControlMainPage ( _viewModel ) ) ;
14- }
10+ public EditorControlPage ( )
11+ {
12+ _viewModel = new EditorViewModel ( ) ;
13+ PushAsync ( new EditorControlMainPage ( _viewModel ) ) ;
14+ }
1515}
1616
1717public partial class EditorControlMainPage : ContentPage
1818{
19- private EditorViewModel _viewModel ;
20-
21- public EditorControlMainPage ( EditorViewModel viewModel )
22- {
23- InitializeComponent ( ) ;
24- _viewModel = viewModel ;
25- BindingContext = _viewModel ;
26- EditorControl . PropertyChanged += UpdateEditorControl ;
27- }
28-
29- private async void NavigateToOptionsPage_Clicked ( object sender , EventArgs e )
30- {
31- BindingContext = _viewModel = new EditorViewModel ( ) ;
32- _viewModel . Text = "Test Editor" ;
33- _viewModel . Placeholder = "Enter text here" ;
34- _viewModel . VerticalTextAlignment = TextAlignment . End ;
35- _viewModel . CursorPosition = 0 ;
36- _viewModel . SelectionLength = 0 ;
37- _viewModel . HeightRequest = - 1 ;
38- await Navigation . PushAsync ( new EditorOptionsPage ( _viewModel ) ) ;
39- }
40-
41- private void CursorPositionButton_Clicked ( object sender , EventArgs e )
42- {
43- if ( int . TryParse ( CursorPositionEntry . Text , out int cursorPosition ) )
44- {
45- _viewModel . CursorPosition = cursorPosition ;
46- }
47- }
48-
49- private void SelectionLength_Clicked ( object sender , EventArgs e )
50- {
51- if ( int . TryParse ( SelectionLengthEntry . Text , out int selectionLength ) )
52- {
53- _viewModel . SelectionLength = selectionLength ;
54- }
55- }
56-
57- private void OnUpdateCursorAndSelectionClicked ( object sender , EventArgs e )
58- {
59- if ( int . TryParse ( CursorPositionEntry . Text , out int cursorPosition ) )
60- {
61- EditorControl . Focus ( ) ;
62- EditorControl . CursorPosition = cursorPosition ;
63-
64- if ( BindingContext is EditorViewModel vm )
65- vm . CursorPosition = cursorPosition ;
66- }
67-
68- if ( int . TryParse ( SelectionLengthEntry . Text , out int selectionLength ) )
69- {
70- EditorControl . Focus ( ) ;
71- EditorControl . SelectionLength = selectionLength ;
72-
73- if ( BindingContext is EditorViewModel vm )
74- vm . SelectionLength = selectionLength ;
75- }
76- CursorPositionEntry . Text = EditorControl . CursorPosition . ToString ( ) ;
77- SelectionLengthEntry . Text = EditorControl . SelectionLength . ToString ( ) ;
78- }
79-
80- void UpdateEditorControl ( object sender , PropertyChangedEventArgs args )
81- {
82- if ( args . PropertyName == Editor . CursorPositionProperty . PropertyName )
83- CursorPositionEntry . Text = EditorControl . CursorPosition . ToString ( ) ;
84- else if ( args . PropertyName == Editor . SelectionLengthProperty . PropertyName )
85- SelectionLengthEntry . Text = EditorControl . SelectionLength . ToString ( ) ;
86- }
87-
88- private void EditorControl_TextChanged ( object sender , TextChangedEventArgs e )
89- {
90- string eventInfo = $ "TextChanged: Old='{ e . OldTextValue } ', New='{ e . NewTextValue } '";
91-
92- if ( BindingContext is EditorViewModel vm )
93- {
94- vm . TextChangedText = eventInfo ;
95- }
96- }
97-
98- private void EditorControl_Completed ( object sender , EventArgs e )
99- {
100- string eventInfo = $ "Completed: Event Triggered";
101-
102- if ( BindingContext is EditorViewModel vm )
103- {
104- vm . CompletedText = eventInfo ;
105- }
106- }
107-
108- private void EditorControl_Focused ( object sender , FocusEventArgs e )
109- {
110- string eventInfo = $ "Focused: Event Triggered";
111-
112- if ( BindingContext is EditorViewModel vm )
113- {
114- vm . FocusedText = eventInfo ;
115- }
116- }
117-
118- private void EditorControl_Unfocused ( object sender , FocusEventArgs e )
119- {
120- string eventInfo = $ "Unfocused: Event Triggered";
121-
122- if ( BindingContext is EditorViewModel vm )
123- {
124- vm . UnfocusedText = eventInfo ;
125- }
126- }
19+ private EditorViewModel _viewModel ;
20+
21+ public EditorControlMainPage ( EditorViewModel viewModel )
22+ {
23+ InitializeComponent ( ) ;
24+ _viewModel = viewModel ;
25+ BindingContext = _viewModel ;
26+ EditorControl . PropertyChanged += UpdateEditorControl ;
27+ }
28+
29+ private async void NavigateToOptionsPage_Clicked ( object sender , EventArgs e )
30+ {
31+ BindingContext = _viewModel = new EditorViewModel ( ) ;
32+ _viewModel . Text = "Test Editor" ;
33+ _viewModel . Placeholder = "Enter text here" ;
34+ _viewModel . VerticalTextAlignment = TextAlignment . End ;
35+ _viewModel . CursorPosition = 0 ;
36+ _viewModel . SelectionLength = 0 ;
37+ _viewModel . HeightRequest = - 1 ;
38+ await Navigation . PushAsync ( new EditorOptionsPage ( _viewModel ) ) ;
39+ }
40+
41+ private void CursorPositionButton_Clicked ( object sender , EventArgs e )
42+ {
43+ if ( int . TryParse ( CursorPositionEntry . Text , out int cursorPosition ) )
44+ {
45+ _viewModel . CursorPosition = cursorPosition ;
46+ }
47+ }
48+
49+ private void SelectionLength_Clicked ( object sender , EventArgs e )
50+ {
51+ if ( int . TryParse ( SelectionLengthEntry . Text , out int selectionLength ) )
52+ {
53+ _viewModel . SelectionLength = selectionLength ;
54+ }
55+ }
56+
57+ private void OnUpdateCursorAndSelectionClicked ( object sender , EventArgs e )
58+ {
59+ if ( int . TryParse ( CursorPositionEntry . Text , out int cursorPosition ) )
60+ {
61+ EditorControl . Focus ( ) ;
62+ EditorControl . CursorPosition = cursorPosition ;
63+
64+ if ( BindingContext is EditorViewModel vm )
65+ vm . CursorPosition = cursorPosition ;
66+ }
67+
68+ if ( int . TryParse ( SelectionLengthEntry . Text , out int selectionLength ) )
69+ {
70+ EditorControl . Focus ( ) ;
71+ EditorControl . SelectionLength = selectionLength ;
72+
73+ if ( BindingContext is EditorViewModel vm )
74+ vm . SelectionLength = selectionLength ;
75+ }
76+ CursorPositionEntry . Text = EditorControl . CursorPosition . ToString ( ) ;
77+ SelectionLengthEntry . Text = EditorControl . SelectionLength . ToString ( ) ;
78+ }
79+
80+ void UpdateEditorControl ( object sender , PropertyChangedEventArgs args )
81+ {
82+ if ( args . PropertyName == Editor . CursorPositionProperty . PropertyName )
83+ CursorPositionEntry . Text = EditorControl . CursorPosition . ToString ( ) ;
84+ else if ( args . PropertyName == Editor . SelectionLengthProperty . PropertyName )
85+ SelectionLengthEntry . Text = EditorControl . SelectionLength . ToString ( ) ;
86+ }
87+
88+ private void EditorControl_TextChanged ( object sender , TextChangedEventArgs e )
89+ {
90+ string eventInfo = $ "TextChanged: Old='{ e . OldTextValue } ', New='{ e . NewTextValue } '";
91+
92+ if ( BindingContext is EditorViewModel vm )
93+ {
94+ vm . TextChangedText = eventInfo ;
95+ }
96+ }
97+
98+ private void EditorControl_Completed ( object sender , EventArgs e )
99+ {
100+ string eventInfo = $ "Completed: Event Triggered";
101+
102+ if ( BindingContext is EditorViewModel vm )
103+ {
104+ vm . CompletedText = eventInfo ;
105+ }
106+ }
107+
108+ private void EditorControl_Focused ( object sender , FocusEventArgs e )
109+ {
110+ string eventInfo = $ "Focused: Event Triggered";
111+
112+ if ( BindingContext is EditorViewModel vm )
113+ {
114+ vm . FocusedText = eventInfo ;
115+ }
116+ }
117+
118+ private void EditorControl_Unfocused ( object sender , FocusEventArgs e )
119+ {
120+ string eventInfo = $ "Unfocused: Event Triggered";
121+
122+ if ( BindingContext is EditorViewModel vm )
123+ {
124+ vm . UnfocusedText = eventInfo ;
125+ }
126+ }
127127}
0 commit comments