i am trying to mask xamdatagrid fields so they accept a certain amount of characters. the below code works to an extent. My first problem is that when i enter data into this field, leave, then come back for edit it is hiding the text in the control. My second question would be how can i make this more generic to use with multiple fields as i have quite a few fields that need to allow only 50 characters in this grid.
thanks in advance
<igDP:Field Name="ID" Label="{Binding Path=Id, Source={x:Static Internationalization:CultureResources.CultureStrings}}"> <igDP:Field.Settings> <igDP:FieldSettings> <igDP:FieldSettings.EditorStyle> <Style TargetType="{x:Type igEditors:XamMaskedEditor}" > <Setter Property="Mask" Value="aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"/> </Style> </igDP:FieldSettings.EditorStyle> </igDP:FieldSettings> </igDP:Field.Settings> </igDP:Field>
you solution solved my problem.
Hello,
I am just checking your progress on the issue.
If you require any further assistance please do not hesitate to ask.
Sincerely,
Ekaterina
Developer Support Engineer
Infragistics
www.infragistics.com/support
Hello Pete,
Thank you for your feedback.
The designed behavior of this control is to move the focus to the right corner of the text field when highlighted. The cursor also disappears – that’s why I avoid selecting any text, that was in order to place the cursor in the beginning of the text area and make it visible. Nevertheless there is a way to select the whole text and still force the focus to move to the begging of the text. You can achieve that manually by clicking somewhere on the xamMaskEditors text field and pressing shft+Home – this will select the text from the current cursor position to the beginning. You can do that programmatically using SendKeys class’s method SendWait.
Here is a corresponding sample:
private void XamMaskedEditor_EditModeStarted(object sender, Infragistics.Windows.Editors.Events.EditModeStartedEventArgs e)
{
SendKeys.SendWait("{END}");
SendKeys.SendWait("+{HOME}");
}
As to your second issue – I was using your sample mask (“aaaa…”) for my example. This “a” represents alphanumeric character placeholder and you would not be able to use special symbols including space. To allow this characters simple use different mask value, that satisfy your custom requirements. Information on masks can be found here:
http://help.infragistics.com/NetAdvantage/WPF/2011.2/CLR4.0/?page=xamInputs_Masks.html
An example for mask that allows spacing is {char:n:s}
Please let me know if my sample meets your requirements or I have misunderstood you at some point.
Infragistics Inc.
it is now putting the cursor at the beginning, however the field is no longer highlighted and the spacebar does not work.
thanks again,
appreciate all your help thus far
I have been investigating your new requirements and in order to place the cursor in the beginning of the edirot’s text you can handle the XamMaskedEditor’s EditModeStarted event by setting an event Setter in the style, like this:
<Grid.Resources>
<Style TargetType="{x:Type igEditors:XamMaskedEditor}" >
<Setter Property="Mask" Value="aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"/>
<Setter Property="Background" Value="AntiqueWhite"/>
<EventSetter Event="EditModeStarted" Handler="XamMaskedEditor_EditModeStarted"/>
</Style>
</Grid.Resources>
and do the following in the code behind
if ((e.Source as XamMaskedEditor) != null)
(e.Source as XamMaskedEditor).SelectionLength = 0;
(e.Source as XamMaskedEditor).SelectionStart = 0;
If you have further concerns on that matter please do not hesitate to ask.