Hi,
I'm using a XamDataGrid. One of its columns is a bound integer field. Whenever I edit the value and type a non-integer value (e.g. 'test') there would be a validation error stating that "Value 'test' could not be converted." I would like to translate this message into a different language when the user changes culture. I believe I have to use an Infragistics resource customizer to accomplish this, but I cannot find this specific resource. I have been trying to find it via the following link:
http://help.infragistics.com/Help/NetAdvantage/WPF/2011.2/CLR4.0/html/WPF_Customize_Assembly_Resource_Strings.html
I have been searching for "Value '{0}' could not be converted." but cannot seem to find it in any of the links on that page. Where is it located?
I'm using netAdvantage v11.2
Regards, Stefan
Hello,
Thank you for your feedback. I am glad that you resolved your issue and I believe that other community members may benefit from this as well.
Thanks again.
Setting the DataType to Double prevents users from entering incorrect characters, but it is also limited to the current UI culture only. When the culture is switched online, the control still displays the same number separator character (e.g. a dot in English). But I understand that this is a WPF problem and so it is not related to Infragistics. So, I'll continue my search on my own. Maybe I can still go with the converter approach here, I'll try it out.
Thanks for your help!
I modified the sample, so now the user is not able to enter string values. I set the UnboundField DataType Property to Double, so now only numbers can be entered. Also I can say that the tooltip for the conversion comes from the .NET. If you still want to be able to enter characters you can use a converter to set the Tooltip for all kind of errors that may occur in the Field.
Hope this helps you.
Oh, and here is that code I tried:
The tooltip in the DataTemplate:
<ToolTip>
<ToolTip.Content>
<MultiBinding Converter="{StaticResource TooltipTextConverter2}">
<Binding Path="Host" />
<Binding Path="Host.DataError" />
<Binding Path="Host.Editor.Value" />
</MultiBinding>
</ToolTip.Content>
</ToolTip>
The XAML is changed into:
public class TooltipTextConverter2 : IMultiValueConverter { public object Convert(object[] values, Type targetType, object parameter, CultureInfo culture) { if (values[0] == DependencyProperty.UnsetValue || values[1] == DependencyProperty.UnsetValue || values[1] == null) return DependencyProperty.UnsetValue; CellValuePresenter cellValuePresenter = values[0] as CellValuePresenter; string error = values[1].ToString(); object editorValue = cellValuePresenter.Editor.Value; string editorValueType = editorValue.GetType().ToString(); string errorMessageToTranslate = string.Format("Value '{0}' could not be converted.", cellValuePresenter.Value); if ((cellValuePresenter).DataError.ToString().Equals(errorMessageToTranslate, StringComparison.InvariantCultureIgnoreCase)) { return "My custom text" + cellValuePresenter.Value.ToString(); } return cellValuePresenter.DataError; } public object[] ConvertBack(object value, Type[] targetTypes, object parameter, CultureInfo culture) { throw new NotImplementedException(); } }
Hi Stefan,
Very close, but still not 100% correct. The right message is displayed in both cases separately, but not when one error follows the other. In order to reproduce this follow these steps:
The other way around also goes wrong.
Obviously, the binding is not refreshed after the value in the textbox changes. Therefore, I already tried to replace the converter with a multivalueconverter and then add a binding to the actual textbox editor value and the dataerror as well (so you have 3 bindings in total; Host, Host.DataError and Host.Editor.Value). This fixes the first scenario (first 'abc', then -50), but not the other way around. This is because the old error message is still cached in the DataError property. It seems the IDataErrorInfo message 'overrules' the converter error message. Any thoughts?