【原创】Silverlight之TextBox的LostFocus、GotFocus事件

<TextBox x:Name="txtCount" Width="200" Height="35" GotFocus="txtCount_GotFocus"


LostFocus
="txtCount_LostFocus" ></TextBox>

然后在后台cs文件中分别对OnGotFocus和OnLostFocus两个方法做处理:

Code highlighting produced by Actipro CodeHighlighter (freeware)
http://www.CodeHighlighter.com/-->private void txtCount_GotFocus(object sender, RoutedEventArgs e)

{

      this.txtCount.Foreground = new SolidColorBrush(Colors.Red);
}

 

private void txtCount_LostFocus(object sender, RoutedEventArgs e)

{
    this.txtCount.Foreground = new SolidColorBrush(Colors.LightGray);

}

搞定之后,运行,当鼠标焦点落在txtCount上时,文字呈红色:

  当焦点移开后,文字呈浅灰色: 

MSDN 查阅:

https://msdn.microsoft.com/zh-cn/library/system.windows.controls.textbox_events(v=vs.95).aspx

 名称说明
公共事件 受 Silverlight for Windows Phone 支持 BindingValidationError 在绑定源报告数据验证错误时发生。 (继承自 FrameworkElement。)
公共事件 DataContextChanged 当此元素的数据上下文更改时发生。 (继承自 FrameworkElement。)
公共事件 受 Silverlight for Windows Phone 支持 DoubleTap 在此 UIElement 上方提交 DoubleTap 手势时发生。 (继承自 UIElement。)
公共事件 DragEnter 在输入系统报告将此元素作为目标的基础拖动事件时发生。 (继承自 UIElement。)
公共事件 DragLeave 在输入系统报告将此元素作为来源的基础拖动事件时发生。 (继承自 UIElement。)
公共事件 DragOver 在输入系统报告将此元素作为潜在放置目标的基础拖动事件时发生。 (继承自 UIElement。)
公共事件 Drop 在输入系统报告将此元素作为放置目标的基础放置事件时发生。 (继承自 UIElement。)
公共事件 受 Silverlight for Windows Phone 支持 GotFocus 当 UIElement 收到焦点时发生。 (继承自 UIElement。)
公共事件 受 Silverlight for Windows Phone 支持 Hold 在此 UIElement 上方提交 Hold 手势时发生。 (继承自 UIElement。)
公共事件 受 Silverlight for Windows Phone 支持 IsEnabledChanged 当 IsEnabled 属性更改时发生。 (继承自 Control。)
公共事件 受 Silverlight for Windows Phone 支持 KeyDown 在 UIElement 具有焦点的情况下按下键盘上的某个键时发生。 (继承自 UIElement。)
公共事件 受 Silverlight for Windows Phone 支持 KeyUp 在 UIElement 具有焦点的情况下释放键盘上的某个键时发生。 (继承自 UIElement。)
公共事件 受 Silverlight for Windows Phone 支持 LayoutUpdated 当 Silverlight 可视化树的布局更改时发生。 (继承自 FrameworkElement。)
公共事件 受 Silverlight for Windows Phone 支持 Loaded 当已构造 FrameworkElement 并将其添加到对象树中时发生。 (继承自 FrameworkElement。)
公共事件 受 Silverlight for Windows Phone 支持 LostFocus 当 UIElement 失去焦点时发生。 (继承自 UIElement。)
公共事件 受 Silverlight for Windows Phone 支持 LostMouseCapture 在 UIElement 失去鼠标捕获时发生。 (继承自 UIElement。)
公共事件 受 Silverlight for Windows Phone 支持 ManipulationCompleted 对于 UIElement 的操作和延时完毕时发生。 (继承自 UIElement。)
公共事件 受 Silverlight for Windows Phone 支持 ManipulationDelta 当输入设备在操作期间更改位置时发生。 (继承自 UIElement。)
公共事件 受 Silverlight for Windows Phone 支持 ManipulationStarted 当输入设备对 UIElement 开始操作时发生。 (继承自 UIElement。)
公共事件 MediaCommand 在按下遥控器上的某个按钮时发生。 (继承自 UIElement。)
公共事件 受 Silverlight for Windows Phone 支持 MouseEnter 当鼠标(或触笔)进入 UIElement 的边界区域时发生。 (继承自 UIElement。)
公共事件 受 Silverlight for Windows Phone 支持 MouseLeave 当鼠标(或触笔)离开 UIElement 的边界区域时发生。 (继承自 UIElement。)
公共事件 受 Silverlight for Windows Phone 支持 MouseLeftButtonDown 当按下鼠标左键(或触笔的笔尖接触 Tablet)并且鼠标指针悬停在 UIElement 上时发生。 (继承自UIElement。)
公共事件 受 Silverlight for Windows Phone 支持 MouseLeftButtonUp 当鼠标(或触笔)悬停在 UIElement 上(或 UIElement 具有鼠标捕获)并且用户松开鼠标左键(或从 Tablet 上移开触笔的笔尖)时发生。 (继承自 UIElement。)
公共事件 受 Silverlight for Windows Phone 支持 MouseMove 当鼠标(或触笔)的坐标位置更改并且悬停在 UIElement 上(或 UIElement 具有鼠标捕获)时发生。 (继承自 UIElement。)
公共事件 MouseRightButtonDown 当鼠标指针位于 UIElement 上并按下鼠标右键时发生。 (继承自 UIElement。)
公共事件 MouseRightButtonUp 当鼠标指针位于 UIElement 上并释放鼠标右键时发生。 但是,只有在调用方将前面的MouseRightButtonDown 事件标记为“已处理”时才引发此事件;请参见“备注”。 (继承自UIElement。)
公共事件 受 Silverlight for Windows Phone 支持 MouseWheel 在以下情况下发生:当鼠标指针悬停在 UIElement 上时或 UIElement 具有焦点时,用户滚动鼠标滚轮。 (继承自 UIElement。)
公共事件 受 Silverlight for Windows Phone 支持 SelectionChanged 在文本选定内容更改后发生。
公共事件 受 Silverlight for Windows Phone 支持 SizeChanged 当 FrameworkElement 上的 ActualHeight 或 ActualWidth 属性的值发生更改时发生。 (继承自FrameworkElement。)
公共事件 受 Silverlight for Windows Phone 支持 Tap 在此 UIElement 上方提交 Tap 手势时发生。 (继承自 UIElement。)
公共事件 受 Silverlight for Windows Phone 支持 TextChanged 在文本框中的内容更改时发生。
公共事件 受 Silverlight for Windows Phone 支持 TextInput 在 UI 元素以与设备无关的方式获取文本时发生。 (继承自 UIElement。)
公共事件 受 Silverlight for Windows Phone 支持 TextInputStart 在 UI 元素以与设备无关的方式最初获取文本时发生。 (继承自 UIElement。)
公共事件 受 Silverlight for Windows Phone 支持 TextInputUpdate 当通过输入方法编辑器 (IME) 继续编写文本时发生。 (继承自 UIElement。)
公共事件 受 Silverlight for Windows Phone 支持 Unloaded 当此对象不再与主对象树连接时发生。 (继承自 FrameworkElement。)
原文地址:https://www.cnblogs.com/x-poior/p/4971696.html