Browse Source

Fix TextBox selection.

pull/58/head
Steven Kirk 12 years ago
parent
commit
1fe10092d9
  1. 28
      Perspex.Controls/TextBox.cs
  2. 2
      Perspex.Themes.Default/TextBoxStyle.cs

28
Perspex.Controls/TextBox.cs

@ -112,20 +112,8 @@ namespace Perspex.Controls
protected override void OnTemplateApplied() protected override void OnTemplateApplied()
{ {
this.presenter = this.GetTemplateChild<TextPresenter>("textPresenter"); this.presenter = this.GetTemplateChild<TextPresenter>("textPresenter");
} this.presenter.GotFocus += PresenterGotFocus;
this.presenter.LostFocus += PresenterLostFocus;
protected override void OnGotFocus(GotFocusEventArgs e)
{
base.OnGotFocus(e);
this.presenter.ShowCaret();
}
protected override void OnLostFocus(RoutedEventArgs e)
{
base.OnLostFocus(e);
this.SelectionStart = 0;
this.SelectionEnd = 0;
this.presenter.HideCaret();
} }
protected override void OnKeyDown(KeyEventArgs e) protected override void OnKeyDown(KeyEventArgs e)
@ -451,5 +439,17 @@ namespace Perspex.Controls
return i; return i;
} }
private void PresenterGotFocus(object sender, RoutedEventArgs e)
{
this.presenter.ShowCaret();
}
private void PresenterLostFocus(object sender, RoutedEventArgs e)
{
this.SelectionStart = 0;
this.SelectionEnd = 0;
this.presenter.HideCaret();
}
} }
} }

2
Perspex.Themes.Default/TextBoxStyle.cs

@ -60,7 +60,7 @@ namespace Perspex.Themes.Default
[~TextPresenter.CaretIndexProperty] = control[~TextBox.CaretIndexProperty], [~TextPresenter.CaretIndexProperty] = control[~TextBox.CaretIndexProperty],
[~TextPresenter.SelectionStartProperty] = control[~TextBox.SelectionStartProperty], [~TextPresenter.SelectionStartProperty] = control[~TextBox.SelectionStartProperty],
[~TextPresenter.SelectionEndProperty] = control[~TextBox.SelectionEndProperty], [~TextPresenter.SelectionEndProperty] = control[~TextBox.SelectionEndProperty],
[~~TextPresenter.TextProperty] = control[~~TextBox.TextProperty], [~TextPresenter.TextProperty] = control[~TextBox.TextProperty],
[~TextPresenter.TextWrappingProperty] = control[~TextBox.TextWrappingProperty], [~TextPresenter.TextWrappingProperty] = control[~TextBox.TextWrappingProperty],
} }
} }

Loading…
Cancel
Save