Hi,
I have several types of editors on a page. I want when the users TAB to a control or click on it, the entire text or number to be selected.
By default the editors would put the cursor at the beginning of the control.
What do I need to do for the editors to select the entire text or number.
Thanks very much in advance.
Dimitar
Hy.
I used the properties SelectionStart and SelectionLength for XamTextEditor and it's working. Here is the example. Maybe it will help.
Nico
<Window x:Class="WpfApplication1.Window1"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="Window1" Height="300" Width="300" xmlns:my="clr-namespace:Infragistics.Windows.Editors;assembly=Infragistics3.Wpf.Editors.v7.2">
<Grid>
<my:XamTextEditor Height="21.277" Margin="66,51,79,0" Name="xamComboEditor1" VerticalAlignment="Top" Text="aaaaaaa" />
<my:XamTextEditor Height="21.277" Margin="72,105,79,0" Name="xamComboEditor2" VerticalAlignment="Top" Text="bbbbbbbb" GotFocus="xamComboEditor2_GotFocus"/>
</Window>
{
xamComboEditor2.SelectionStart = 0;
xamComboEditor2.SelectionLength = xamComboEditor2.Text.Length;
}
That is definitely an option. However, I was hoping I can do that through a style so I can apply it to all controls of a certain style regardless of what window they are on.
So far we have not found a way.
Thanks.
Hello Mitashki,
You can use a style with an EventSetter and a little bit of code behind to get what you want.
In the XAML add the style definition. Change x:Key to a style name if you prefer to apply the style to each instance of an editor rather than have it apply automatically to all XamTextEditors.
<Style x:Key="{x:Type igEditors:XamTextEditor}" TargetType="{x:Type igEditors:XamTextEditor}"> <EventSetter Event="GotFocus" Handler="HandleFocusEditorEvent"/></Style>
In the code-behind add the event handler definition:
private void HandleFocusEditorEvent(object sender, RoutedEventArgs e){ ((XamTextEditor)sender).SelectAll();}
This will cause the XamTextEditor to select all text in itself every time it gains key focus.
Thanks Curtis!
We put the code behind in the resource dictionary and that seemed to do it for all editors.
Thanks Curtis - we are working on a pretty large project. I'll try to create a simpler, smaller project that reproduces the problem.
I'm not sure what an Edit Edit Control Template is. If you post the XAML which breaks the event handler, I will try to replicate the problem.
Thanks,
This worked well until one of our graphics designers used Blend to create an "Edit Edit Control Template". The event is no longer firing in this case. Is there anyway to add this style to the "Edit Edit Control Template" so the event will fire again?