我正在研究世界森林论坛的申请,其中我有一些显示美元数额的文本箱。 我只想在案文箱内选择所有内容,只要把重点放在文字箱上。
为了达到同样的目的,我使用了“选择一切”方法,在戈特Focus活动上使用插文,但是它不像希望的那样工作。
让我知道我如何能够发挥作用。 成就
我正在研究世界森林论坛的申请,其中我有一些显示美元数额的文本箱。 我只想在案文箱内选择所有内容,只要把重点放在文字箱上。
为了达到同样的目的,我使用了“选择一切”方法,在戈特Focus活动上使用插文,但是它不像希望的那样工作。
让我知道我如何能够发挥作用。 成就
on startup, register a global event handler for textbox e.g
EventManager.RegisterClassHandler(typeof(System.Windows.Controls.Primitives.TextBoxBase), UIElement.GotFocusEvent, new RoutedEventHandler(TextBoxBaseGotFocus));
采用文本BoxBaseGotFocus方法,即:
private static void TextBoxBaseGotFocus(object sender, RoutedEventArgs e)
{
// Get the TextBoxBase
var elem = sender as System.Windows.Controls.Primitives.TextBoxBase;
if (elem != null)
{
elem.SelectAll();
}
}
你们可以为此建立附属行为,并将之用于所希望的文本箱。 The approch is details here -
http://eladm.wordpress.com/2009/04/02/attapple-behavior/
这些行为守则也可在以下网站查阅:here &
如果您在申请中想到所有文本箱,以不实的方式来考虑,那么:
Have you tried handling FocusableChanged event http://msdn.microsoft.com/en-us/library/system.windows.uielement.focusablechanged.aspx
You can check IsFocused inside FocusableChanged event handler. if IsFocused is true, you can call SelectAll Following is the pseudo code
textBox.FocusableChanged += (s,e) =>
{
if(textBox.IsFocused)
testBox.SelectAll();
}
EDIT1
As Above is not working, You can try FocusManger.GetFocusedElement.
determining-the-focused-element
public DebugFocusedElementProxy()
{
var timer = new DispatcherTimer();
timer.Interval = TimeSpan.FromMilliseconds(100);
timer.Tick += (o, ea) =>
{
var fe = FocusManager.GetFocusedElement();
if (fe != null)
{
var element = fe as FrameworkElement;
if (!string.IsNullOrEmpty(element.Name) &&
String.Equals(element.Name, textBox))
{
textBox.SelectAll();
}
}
};
timer.Start();
}
/ 认识到案文 方框SelectAll可能要求打电话到。 发送地址:
As a learning experience I recently tried implementing Quicksort with 3 way partitioning in C#. Apart from needing to add an extra range check on the left/right variables before the recursive call, ...
I m the only developer in my company, and am getting along well as an autodidact, but I know I m missing out on the education one gets from working with and having code reviewed by more senior devs. ...
I have two EF entities. One has a property called HouseNumber. The other has two properties, one called StartHouseNumber and one called EndHouseNumber. I want to create a many to many association ...
I m using decimal type (.net), and I want to see if two numbers are equal. But I only want to be accurate to 10 decimal places. For example take these three numbers. I want them all to be equal. 0....
I m creating an STA version of the SynchronizationContext for use in Windows Workflow 4.0. I m wondering what to do about exceptions when Post-ing callbacks. The SynchronizationContext can be used ...
I ve got some code which sets up a datacontext. Often enough, the datacontext should be set to some underlying data collection, such as an ObservableCollection - but occasionally I d like to set it ...
I am building an application with C#. I managed to turn this into a single instance application by checking if the same process is already running. Process[] pname = Process.GetProcessesByName("...
NOTE I have asked the related question (with an accepted answer): How to combine DataTrigger and Trigger? I think I need to combine an EventTrigger and a DataTrigger to achieve what I m after: when ...