Browse Source

Correctly handle TextPresenter focus events.

Fixes #27.
pull/39/head
Steven Kirk 12 years ago
parent
commit
bedd894f29
  1. 35
      Perspex.Controls/Presenters/TextPresenter.cs
  2. 2
      TestApplication/Program.cs

35
Perspex.Controls/Presenters/TextPresenter.cs

@ -13,6 +13,7 @@ namespace Perspex.Controls.Presenters
using Perspex.Controls.Primitives;
using Perspex.Controls.Utils;
using Perspex.Input;
using Perspex.Interactivity;
using Perspex.Media;
using Perspex.Threading;
using Perspex.VisualTree;
@ -99,21 +100,6 @@ namespace Perspex.Controls.Presenters
return hit.TextPosition + (hit.IsTrailing ? 1 : 0);
}
public new void GotFocus()
{
this.caretBlink = true;
this.caretTimer.Start();
}
public new void LostFocus()
{
this.SelectionStart = 0;
this.SelectionEnd = 0;
this.caretTimer.Stop();
this.InvalidateVisual();
}
public override void Render(IDrawingContext context)
{
var selectionStart = this.SelectionStart;
@ -199,6 +185,25 @@ namespace Perspex.Controls.Presenters
}
}
protected override void OnGotFocus(RoutedEventArgs e)
{
base.OnGotFocus(e);
this.caretBlink = true;
this.caretTimer.Start();
this.InvalidateVisual();
}
protected override void OnLostFocus(RoutedEventArgs e)
{
base.OnLostFocus(e);
this.SelectionStart = 0;
this.SelectionEnd = 0;
this.caretTimer.Stop();
this.InvalidateVisual();
}
protected override void OnKeyDown(KeyEventArgs e)
{
string text = this.Text ?? string.Empty;

2
TestApplication/Program.cs

@ -302,7 +302,7 @@ namespace TestApplication
},
new TextBox
{
Text = "A non-wrapping text box. Lorem ipsum dolor sit amet.",
//Text = "A non-wrapping text box. Lorem ipsum dolor sit amet.",
TextWrapping = TextWrapping.NoWrap,
},
new TextBox

Loading…
Cancel
Save