Hello Infragistics.
I have a Problem with the XamNumericEditor in a XamDataGrid. The mask propperty I set is not working.
Background:
I have a DataTable and fill with this object the XamDataGrid, when the fields are initialized i catch the FieldLayoutInitialized Event and set the MaskProperty for all numeric fields with this pice of Code:
f.SetValue(XamNumericEditor.FormatProperty, GetFromatProperty(maxvalue)); f.SetValue(XamNumericEditor.MaskProperty, "{}{" + $"double:{befor}.{header.FieldDecimal}" + "}"); f.SetValue(XamNumericEditor.ValueConstraintProperty, constraint); f.SetValue(XamNumericEditor.ValueTypeProperty, typeof(double));
For every field i have to calulate a new Mask.
Unfortunately there is somethink worng in thouse lines.
Thanks for the help,
Jan
Hello Jan,
I recommend following the example for setting the Mask property via XAML for the field you need instead of SetValue and let me know if you are still experiencing the same issue.
http://help.infragistics.com/Help/Doc/WPF/2013.1/CLR4.0/html/xamNumericEditor_Using_xamNumericEditor_as_a_Field_in_xamDataGrid.html
ex.
<igDP:XamDataGrid.FieldLayouts> <igDP:FieldLayout> <igDP:FieldLayout.Fields> <igDP:Field Name="ProductName" /> <igDP:Field Name="CostPerUnit" > <igDP:Field.Settings> <igDP:FieldSettings EditAsType="{x:Type sys:Double}"> <igDP:FieldSettings.EditorStyle> <Style TargetType="{x:Type igEditors:XamNumericEditor}" > <Setter Property="Mask" Value="{}{double:7.2:c}" /> </Style> </igDP:FieldSettings.EditorStyle> </igDP:FieldSettings> </igDP:Field.Settings> </igDP:Field> </igDP:FieldLayout.Fields> </igDP:FieldLayout> </igDP:XamDataGrid.FieldLayouts> ...
<
igDP:XamDataGrid.FieldLayouts
>
igDP:FieldLayout
igDP:FieldLayout.Fields
igDP:Field
Name
=
ProductName
/>
CostPerUnit
igDP:Field.Settings
igDP:FieldSettings
EditAsType=
{x:Type sys:Double}
igDP:FieldSettings.EditorStyle
Style
TargetType
{x:Type igEditors:XamNumericEditor}
Setter
Property
Mask
Value
{}{double:7.2:c}
</
Let me know if you have any questions.{code
Hello Michael!
By changing the UI from our old Application to new UI with Infragistics Controls, we want to keep the old resource files for the UI definition. That means I don’t create the UI in XAML, I create it in C#. All we have to do is write a converter from our own resource files to C# controls. There are more reasons why we are going this way. To wrap this up, this is the same reason why I want to set the MaskProperty in the FieldLayoutInitialized event from the XamDataGrid with this line:
field.SetValue(XamNumericEditor.MaskProperty, "{}{" + $"double:{befor}.{header.FieldDecimal}" + "}");
For better understanding I put some example data in the line:
fied.SetValue(XamNumericEditor.MaskProperty, "{}{" + $"double:15.3" + "}");field.SetValue(XamNumericEditor.MaskProperty, "{}{" + $"double:2.2" + "}"); field.SetValue(XamNumericEditor.MaskProperty, "{}{" + $"double:4.2" + "}");
I don’t want to create a Style for every possibility because if we change something in the structure of our fields or add a new field then I have to create a new Style in the worst case. This is why I want to create this on the fly in C# and not in XAML.
Can you show me an example for this?
Thank you for following up. The code you listed will not work because numeric editor properties do not exist on regular field objects. You can solve this, if you are using at 14.2 or later, by using a NumericField instead, which does have a Mask property. In the event you would do something similar to the example below.
For more details about setting up a NumericField please visit out online help:
http://help.infragistics.com/Help/Doc/WPF/2014.2/CLR4.0/html/xamDataGrid_Configuring_Specific_Editor_Fields.html#_Ref388887231
eg.
private void XamDataGrid_FieldLayoutInitialized(object sender, Infragistics.Windows.DataPresenter.Events.FieldLayoutInitializedEventArgs e) { //1. Create NumericFields //2. Determine each field by index/string and set their Mask property foreach (FieldLayout fieldLayout in xdg.FieldLayouts) { foreach (Field field in fieldLayout.Fields) { if (field.DataType == typeof(int)) // replace this with whatever type the field represents { var numericfield = field as NumericField; numericfield.Mask = "{}{double:15.3}"; } } } }
Let me know if you have any questions.
Hello Michael,
thanks for the link. I made a littel sample Application, because it still dosen't work. If you can't solved it i'll make a workaround with strings but i hope you canhelp me on this one!
Thanks for youre patience,
Jan,
You'll need to include a check to determine if the field in indeed a NumericField. I tweaked my code snippet as such to be universal when multiple field types are added to the Fields collection:
private void xdg_FieldLayoutInitialized(object sender, Infragistics.Windows.DataPresenter.Events.FieldLayoutInitializedEventArgs e) { foreach (FieldLayout fieldLayout in xdg.FieldLayouts) { foreach (var field in fieldLayout.Fields) { if (field is NumericField && field.Label.ToString() == "Number3" && field.DataType == typeof(double)) { NumericField nf = field as NumericField; nf.Mask = "###############.###"; } } } }
Please see my attached sample for further details. Thanks again.
Thanks Michael,
I understand my prblem now. You're example is working for me.
I am glad your solution is working now.
Please let us know if you have any more questions.
Regards,