Skip to content

Commit

Permalink
Move event binding into OnHandlerChanged
Browse files Browse the repository at this point in the history
  • Loading branch information
DevFromDownUnder committed Mar 25, 2024
1 parent 85980d8 commit 42355ff
Showing 1 changed file with 9 additions and 2 deletions.
11 changes: 9 additions & 2 deletions src/UraniumUI.Material/Controls/TextField.cs
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,6 @@ public TextField()
EntryView.SetBinding(Entry.IsEnabledProperty, new Binding(nameof(IsEnabled), source: this));
EntryView.SetBinding(Entry.IsReadOnlyProperty, new Binding(nameof(IsReadOnly), source: this));

iconClear.Focused += (s, e) => { ValidateClearButtonFocus(); };

AfterConstructor();
}

Expand All @@ -64,15 +62,19 @@ public TextField()
protected override void OnHandlerChanged()
{
base.OnHandlerChanged();

if (Handler is null)
{
EntryView.TextChanged -= EntryView_TextChanged;
EntryView.Completed -= EntryView_Completed;
iconClear.Focused -= IconClear_Focused;
}
else
{
EntryView.TextChanged += EntryView_TextChanged;
EntryView.Completed += EntryView_Completed;
iconClear.Focused -= IconClear_Focused;

ApplyAttachedProperties();
}
}
Expand Down Expand Up @@ -107,6 +109,11 @@ private void EntryView_Completed(object sender, EventArgs e)
Completed?.Invoke(this, e);
}

private void IconClear_Focused(object sender, FocusEventArgs e)
{
ValidateClearButtonFocus();
}

public void ClearValue()
{
if (IsEnabled)
Expand Down

0 comments on commit 42355ff

Please sign in to comment.