We had a requirement to use xammaskededitor inside a xamgrid . For this I added a customcolumn which has a displaycontrol as a textblock and the editor control as the Xammaskededitor control.
For some reason in edit mode , when the user empties the values for eg : no value , which is equivalent to "__/__/__" according to my mask the under lying View model is not getting updated properyly. If i change it a valid value I can see the view model getting updated and the cell gets updated to the new value.But the problem comes when the user wants to have an empty date value, the cell is retaining the old value because the view model newver gets updated in those scenarios?
I followed the apporach here to add the custom column to the grid.
http://blogs.infragistics.com/blogs/devin_rader/archive/2010/07/08/creating-custom-columns-for-xamgrid.aspx
To Reproduce:
1.Create a xamgrid.bind it to a view model
2. Add a customcolumn to the grid which has TextBlock as the displaycontrol and the XamMaskEditor as the editor control.Bind it two way to the view model.
3. When the user empties the text, the view model is not updated and the cell retains the old value.When the value is set to a valid value it behaves properly.
(I also noticed that when the XamEditor is used as regular control on the form it behaves properly)
You could probably try to workaround this by adding a check in the ConvertBack method of your Converter if the value is "__/__/__" and if so return DateTime.Empty(some not realistic/expected value like DateTime.MinValue) or handle the empty value somehow.
HTH,
Thanks ...Pls let us know at the earliest .
Application went to production with the DataColumn.Users want the maked control but since we found this issue we went ahead with the Datacolumn for the time being.
Hi,
here's what is happening. Because you set the dp.ValidationMode to ValidationMode.LostFocus the masked editor's Value prop is evaluated when the editor gets LostFocus fire. This happens after the call to ResolveValueFromEditor is made - that's why the cell's bound value does not change.
After this the editor gets its LostFocus event which cause him to update the Value then the binding try to update the binding source passing the empty string "__/__/__" then the converter CovertBack method is hit which fails because it returns the value itself which is the empty string. Finally the cell's value remains unchanged.
I am going to contact our dev team to take a look on this.
Regards,
Thanks for the quick reply.We don't want to use the DateColumn, because by default they get rendered as DatePicker and users don't want it.
Our grid's dynamic and have couple of other custom columns which are working fine...
Here's the 3 classes as such and u can easily reproduce the issue
public class CustomDateColumn : EditableColumn
{
protected override ColumnContentProviderBase GenerateContentProvider()
return new CustomDateColumnProvider();
}
public class CustomDateColumnProvider : ColumnContentProviderBase
XamMaskedEditor dp;
TextBlock tb;
public CustomDateColumnProvider()
dp = new XamMaskedEditor();// DatePickerMaskedSingleControl();
dp.Mask = "##/##/##";
dp.PadChar = '_';
// dp.ValueChanged += new RoutedEventHandler(dp_ValueChanged);
dp.DataMode = MaskMode.IncludeLiteralsWithPadding;
dp.DisplayMode = MaskMode.IncludeLiteralsWithPadding;
dp.ValidationMode = ValidationMode.LostFocus;
tb = new TextBlock();
dp.LostFocus += new RoutedEventHandler(dp_LostFocus);
void dp_LostFocus(object sender, RoutedEventArgs e)
public override FrameworkElement ResolveDisplayElement(Cell cell,
System.Windows.Data.Binding cellBinding)
CustomDateColumn column = (CustomDateColumn)cell.Column;
Binding textBinding = new Binding();
textBinding.Path = new PropertyPath(column.Key);
textBinding.Converter = new DateConverter();
textBinding.Mode = BindingMode.TwoWay;
this.tb.SetBinding(TextBlock.TextProperty, textBinding);
return tb;
protected override System.Windows.FrameworkElement ResolveEditorControl(Cell cell, object editorValue, double availableWidth, double availableHeight, Binding editorBinding)
textBinding.Source = cell.Row.Data;
this.dp.SetBinding(XamMaskedEditor.ValueProperty, textBinding);
return this.dp;
public override object ResolveValueFromEditor(Cell cell)
return this.dp.Value;
public class DateConverter : IValueConverter
public object Convert(object value, System.Type targetType, object parameter, System.Globalization.CultureInfo culture)
string retString = string.Empty;
string formatString = "MM/dd/yy"; //Default date format
//return string.Format(System.Convert.ToString(parameter), decimal.Parse(System.Convert.ToString(value)));
if (parameter != null) // default
if (!string.IsNullOrWhiteSpace(parameter.ToString()))
formatString = parameter.ToString().Trim();
if (value != null && !string.IsNullOrWhiteSpace(value.ToString()))
// retString = System.String.Format(formatString, System.Convert.ChangeType(value, typeof(DateTime), null));
DateTime dtOut;
if (DateTime.TryParse(value.ToString(), out dtOut))
retString = System.Convert.ToDateTime(value).ToString(formatString);
else
retString = value.ToString();
return retString;
public object ConvertBack(object value, System.Type targetType, object parameter, System.Globalization.CultureInfo culture)
return value;
if you want to display date it might be better to use DateColumn.
If DateColumnis not an option for you and XamMaskedEditor has to be used you might want to use TemplateColumn. Here is sample xaml:
<ig:TemplateColumn Key="DateProperty"> <ig:TemplateColumn.ItemTemplate> <DataTemplate> <TextBlock Text="{Binding DateProperty}" /> </DataTemplate> </ig:TemplateColumn.ItemTemplate> <ig:TemplateColumn.EditorTemplate> <DataTemplate> <ig:XamMaskedEditor Width="100" Height="20" Culture="en-US" Mask="##/##/####" Text="{Binding DateProperty, Mode=TwoWay}"/> </DataTemplate> </ig:TemplateColumn.EditorTemplate> </ig:TemplateColumn>
Note that the XamMaskedEditor setup from the snippet might not match your scenario exactly but the point is to illustrate the approach.
Custom column is supposed to be used used in more complex scenarios that are not achievable through TemplateColumn or UnboundColumn or if you the column is going to be widely used.
However if you need the custom column solution to work I will need a sample solution or at least some code snippets of the ResolveEditorElement of the custom column so I can look into the issue.