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.
Yes. I did handle that event. But as I told you, after entering that event, it goes to the raisepropertychanged event for the phone number and allots the value. I have posted the code in the above post.
Is it possible for you to send us an isolated sample project, where this is reproduced, so we could be able to investigate it further for you?
Hi Stephan, Sorry I could not recreate it as it is passing through two viewmodels and one webservice. I will have to spend more time to recreate it than solve. I could able to get the phoneNumber property value inside XamGrid CellExitingEditMode
private void XamGrid_CellExitingEditMode(object sender, Infragistics.Controls.Grids.ExitEditingCellEventArgs e) { CompanyPhoneNumbers newPhoneNumber = (CompanyPhoneNumbers)e.Cell.Row.Data; if (newPhoneNumber.PhoneNumber == "--") { // How to access maskeditor here to give the error message }}
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.
Hello,
I am just checking if you require any further assistance on the matter.
Sincerely,
Krasimir, MCPD
Developer Support Supervisor - XAML
Infragistics
www.infragistics.com/support
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 == "--")
Grid grid = e.Editor as Grid;
//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;
}