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)
Hi,
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.
HTH,
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;
Hello,
I sent a sample based on your code above to our engineers for review, and they pointed out some things that are problematic. The two main issues here are:
1. The overridden methods in the custom provider class (CustomDateColumnProvider) should use the Binding objects that are already being passed into them, rather than creating your own Bindings.
2. The Column's ValueConverter and EditorValueConverter properties should be set to use your DateConverter (cf. CustomDateColumn constructor).
Please test the attached sample and let me know if this resolves the issues you are having with the custom date column.
Thanks,
Got the sample...Our major issue is the inability to use the lost_focus event of XamMaskedEditor inside the grid, which I have mentioned in the post...Basically what I was trying to do is when the data entered by the user is invalid , keep the focus on the XamAmskedEditor field .. In the Lost_focus event of the XamMaskedGrid in the Customcolumn the code was, --DateTime.TryParse(the column value ) ----if its an invalid date time , keep the focus on the currently edited XamMasked field..But this was not working, focus will go away regardless of setting the focus back to the cell in edit mode ..
the lost focus issue is still not solved.when the XamMaskedEditor has an invalid date and if we try to handle the that in the lost focus its not working..
this is the lost focus event in the CustomDateColumnProvider.
e)
.Empty;
;
)
.DEFAULT_TXT.Trim()))
dateValue;
dateValue))
((
)sender).Focus();
I might not be clear on your requirements. The sample I attached does not have the LostFocus event wired up, nor does it need to. If you provide an invalid date, the focus is not lost, but it remains in the cell's editor, as expected. Is there a reason why you need to use LostFocus?
u are right ..if u use the XamMaskededitor in the Always mode, then it will stay focus. There also we had found an issue..If the editors value is an invalid date and the user tries to focus on a Dropdownbox some where on the screen and selects a value it still looses focus..Which is Ok..Problem is one of our drop down is allowing the user to put the grid in a read only mode..
When there is a erros in the date editor and the user goes to this drop down and puts the grid in read only mode(none of the cells in the grid is edtable) and comes back to edit mode by selecting the edit option from the drop down..the grid never becomes editable...(the problem I believe is the date picker which was in the edit mode with its focus still on on it) ....We some how solved by using the value changed event and keeping the focus on the cell...
Ideally we wanted to use the LostFocus mode of the control and not the Always mode for 2 reason ..,
1. To only show the error message when the user looses focus as against showing the error message always till the data is corrected
2. Also we wanted to keep the focus on the cell, if the data is bad
As discussed the snippet in the XamMaskedEditor lost focus inside the CustomeDateColumnProvider class ;
It sounds as if you have worked around the issue, but are unable to get the ideal behavior. If you would like me to research this further, please review the attached sample, which is a slight modification of the previous one I provided to make it a little closer to the application you described. (i.e. I merely added a stand-alone dropdown and wired up the LostFocus event.)
If you can either modify this sample, or guide me on how to do so such that it models your current situation....or supply a new sample of your own, I will be sure to investigate further.