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.
I am just checking if you got this worked out or you still require any assistance or clarification on the matter.
Thank you for checking Stephan, Actually the phone number is binded with a property called phonenumber. After the value changed event, it goes to a onpropertychanged event and assigns the same value again. This is a code written by someone and I am debugging it. So still looking for some work arounds in the present code.
Let me know if you have any ideas.
I am just checking the progress of this issue and was wondering if you managed to achieve your goal or if you need any further assistance on the matter.
Hi,
Thanks for checking. I moved on to other defects, I still have this issue.
Following are code related to this.
In xaml
<ig:TemplateColumn Key="PhoneNumber" HeaderText="Phone Number" Width="*"> <ig:TemplateColumn.ItemTemplate> <DataTemplate> <TextBlock Text="{Binding PhoneNumber}" /> </DataTemplate> </ig:TemplateColumn.ItemTemplate> <ig:TemplateColumn.EditorTemplate> <DataTemplate> <ig:XamMaskedEditor Mask="999-999-9999CCCCCCCC" Value="{Binding PhoneNumber, Mode=Twoway}" ValueChanged="XamMaskEditor_ValueChanged" AcceptsReturn="True"> </ig:XamMaskedEditor> </DataTemplate> </ig:TemplateColumn.EditorTemplate> </ig:TemplateColumn> </ig:XamGrid.Columns>
Code behind:
private void XamMaskEditor_ValueChanged(object sender, RoutedEventArgs e) { Infragistics.Controls.Editors.XamMaskedEditor xamEditor = (Infragistics.Controls.Editors.XamMaskedEditor)sender; if (xamEditor.Text == "___-___-____________") { xamEditor.ErrorMessage = "Phone Number is not in proper format."; } }
Viewmodel:
[DataMember] public string PhoneNumber { get { return _phoneNumber; } set { if (_phoneNumber != value) { _phoneNumber = value; OnPropertyChanged("PhoneNumber"); } } } private string _phoneNumber;
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;
}