I have a XamMaskedEditor for phone number. When there is no number entered, it leaves back literals(--) in the TextBlock. With options of DisplayMode to Raw or IncludePromtChars, there is no change in the behavior. How to empty the textblock, if no number is typed?
Thanks in advance.
Hello Gayathri,
Thank you for your post. I have been looking into it and I created a sample project for you with the functionality you want. Basically I handled the XamMaskedInput’s ValueChanged event and in the handler I change the Mask if there is value or not. Please let me know if this helps you or you have further questions on this matter.
Looking forward for your reply.
<ig:TemplateColumn.EditorTemplate>
<DataTemplate>
<ig:XamMaskedEditor Mask="999-999-9999CCCCCCCC" x:Name="xamMaskEditor" Value="{Binding PhoneNumber, Mode=Twoway}" AcceptsReturn="True" />
</DataTemplate>
</ig:TemplateColumn.EditorTemplate>
How do I access maskedEditor inside valuechanged event. Can you show me a sample code?. Thanks.
You can get the Editor by using the ExitEditingCellEventArgs' Editor Property. Please let me know if you have further questions on this matter.
I am getting the property inside the ExitEditingCellEventArgs of Xamgrid. Is there a way to access the xamMaskedEditor inside XamGrid's ExitEditingCellEventArgs, as the maskedEditor is a control inside the grid. If so, I can pass the error message to xamMaskedEditor from this event.
Thank you.
You can cast the Editor Property to XamMaskedInput and you will have a reference to the Editor. Once you do this you can set the Error message.
Hope this helps you.
Can you show that line of code for casting the editor to access xamMaskedEditor inside xamgrid_cellexitingEditMode event. Thanks
Hello Geyathri,
Thank you for your post. You can use a simple as cast if the root element of the EditorTempalte is the input:
XamMaskedInput input = e.Editor as XamMaskedInput;
Also, if the e.Editor will return the root element in the EditorTemplate so you have:
<Grid>
<ig:XamMaskedInput
Mask="999-999-9999CCCCCCCC"
Value="{Binding PhoneNumber, Mode=Twoway}"
ValueChanged="XamMaskedInput_ValueChanged"/>
</Grid>
You can use the following code in the event:
Grid grid = e.Editor as Grid;
XamMaskedInput input = grid.Children[0] as XamMaskedInput;
I am attaching a sample application that shows how you can implement this.
Please let me know if you need any further assistance on the matter.
Sincerely,
Krasimir, MCPD
Developer Support Supervisor - XAML
Infragistics
www.infragistics.com/support
Hello,
I am just checking if you require any further assistance on the matter.
Thank you for your reply. I have been looking into the xaml that you have provided and you have two TemplateColumns with different EditorTemplates, which needs to be handled differently in the event. Would you please provide me with the code for the CellExitingEditMode event of the XamGrid, so I can research what might be causing the issue?
Looking forward to hearing from you.
Thank you for the reply. Below is my usercontrol page structure.
I get nullreference again.
<UserControl x:Class="Debi.Sl.Rock.Views.Company.PhoneNumbersView" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:d="http://schemas.microsoft.com/expression/blend/2008" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" xmlns:Controls="clr-namespace:Debi.Sl.Rock.Controls" xmlns:design="clr-namespace:Debi.Sl.Rock.DesignerViewModels.Company" xmlns:sdk="clr-namespace:System.Windows.Controls;assembly=System.Windows.Controls.Data" xmlns:ig="http://schemas.infragistics.com/xaml" xmlns:Converters="clr-namespace:Debi.Sl.Rock.Converters" xmlns:Interactivity="clr-namespace:System.Windows.Interactivity;assembly=System.Windows.Interactivity" xmlns:Behaviors="clr-namespace:Debi.Sl.Rock.Behaviors" mc:Ignorable="d" d:DesignHeight="300" d:DesignWidth="400"> <Controls:CollapsableContent HeaderText="Phone Numbers" IsExpanded="{Binding IsExpanded, Mode=TwoWay}" Style="{StaticResource CompanyCollapsableContentStyle}" d:DataContext="{d:DesignInstance design:PhoneNumbersDesignViewModel, IsDesignTimeCreatable=True}"> <Controls:CollapsableContent.Resources> <Controls:DataContextBinder x:Key="BindingContent" Content="{Binding}" /> <Converters:ComboEditorItemLookupConverter x:Key="LookupConverter" LookupList="{Binding Source={StaticResource BindingContent}, Path=Content.PhoneTypeSearcher}" /> <Converters:PhoneNumberConverter x:Key="PhoneConverter"/> </Controls:CollapsableContent.Resources> <Interactivity:Interaction.Behaviors> <Behaviors:ValidationBehavior HasBindingErrors="{Binding HasBindingErrors, Mode=TwoWay}" /> </Interactivity:Interaction.Behaviors> <ig:XamGrid AutoGenerateColumns="False" Height="200" ItemsSource="{Binding PhoneNumbers}" DeleteKeyAction="DeleteSelectedRows" RowSelectorClicked="XamGrid_RowSelectorClicked" CellExitingEditMode="XamGrid_CellExitingEditMode" RowHover="Row" VerticalAlignment="Top" ColumnWidth="*"> <ig:XamGrid.Columns> <ig:TemplateColumn Key="PhoneTypeId" HeaderText="Phone Type"> <ig:TemplateColumn.ItemTemplate> <DataTemplate> <TextBlock Text="{Binding PhoneTypeId, Converter={StaticResource LookupConverter}}" /> </DataTemplate> </ig:TemplateColumn.ItemTemplate> <ig:TemplateColumn.EditorTemplate> <DataTemplate> <Controls:RockXamComboEditor AutoComplete="True" DisplayMemberPath="Name" SelectedValuePath="Id" SelectedValue="{Binding PhoneTypeId, Mode=TwoWay}" ItemsSource="{Binding Source={StaticResource BindingContent}, Path=Content.PhoneTypes}"> </Controls:RockXamComboEditor> </DataTemplate> </ig:TemplateColumn.EditorTemplate> </ig:TemplateColumn> <ig:TemplateColumn Key="PhoneNumber" HeaderText="Phone Number" Width="*"> <ig:TemplateColumn.ItemTemplate> <DataTemplate> <TextBlock Text="{Binding PhoneNumber, Converter={StaticResource PhoneConverter}}" /> </DataTemplate> </ig:TemplateColumn.ItemTemplate> <ig:TemplateColumn.EditorTemplate> <DataTemplate> <Grid> <ig:XamMaskedEditor Mask="999-999-9999CCCCCCCC" x:Name="xamMask" Value="{Binding PhoneNumber, Mode=Twoway}" ValueChanged="XamMaskEditor_ValueChanged" AcceptsReturn="True"> </ig:XamMaskedEditor> </Grid> </DataTemplate> </ig:TemplateColumn.EditorTemplate> </ig:TemplateColumn> </ig:XamGrid.Columns> <ig:XamGrid.AddNewRowSettings> <ig:AddNewRowSettings AllowAddNewRow="Bottom" IsEnterKeyEditingEnabled="False" IsF2EditingEnabled="True" IsMouseActionEditingEnabled="SingleClick" IsOnCellActiveEditingEnabled="False"/> </ig:XamGrid.AddNewRowSettings> <ig:XamGrid.EditingSettings> <ig:EditingSettings AllowEditing="Row" IsMouseActionEditingEnabled="SingleClick" /> </ig:XamGrid.EditingSettings> <ig:XamGrid.SelectionSettings> <ig:SelectionSettings RowSelection="Multiple" CellClickAction="SelectRow" /> </ig:XamGrid.SelectionSettings> <ig:XamGrid.RowSelectorSettings> <ig:RowSelectorSettings EnableRowNumbering="False" Visibility="Visible" /> </ig:XamGrid.RowSelectorSettings> </ig:XamGrid> </Controls:CollapsableContent></UserControl>
Thank you for your reply. I have been looking into it and I am not able to reproduce this behavior. I am attaching a screenshot that shows that the XamMaskedEditor is found in the event. I assume that you have some other structure in the EditorTemplate and the first child in the root grid is not the XamMaskedEditor. I can suggest double checking the structure of your EditorTempalte and find the right position of the XamMaskedEditor in it.
Please let me know if I can assist you with anything else.
Hi Krasimir, Thanks for the reply. I get a NullReferenceException on XamMaskedEditor. Following is my code.
private void XamGrid_CellExitingEditMode(object sender, Infragistics.Controls.Grids.ExitEditingCellEventArgs e)
{
CompanyPhoneNumbers newPhoneNumber = (CompanyPhoneNumbers)e.Cell.Row.Data;
if (newPhoneNumber.PhoneNumber == "--")
//XamMaskedEditor input= e.Editor as XamMaskedEditor -- this is also throwing nullreference.
XamMaskedEditor input = grid.Children[0] as XamMaskedEditor;
input.ErrorMessage = "Please enter a valid phone Number";
input.Focus();
return;
}