Your Privacy Matters: We use our own and third-party cookies to improve your experience on our website. By continuing to use the website we understand that you accept their use. Cookie Policy
470
Set MaxLength individually
posted

Hi,

I have a XamDataGrid with many Fields that share different styles.

Now each field needs it's MaxLength set individually.

I tried to achieve that by making an attached dependebcyproperty but I have problems accessing ValueConstraint.MaxLength.

This is what I have so far:

using System.Globalization;
using System.Windows;
using Infragistics.Windows.DataPresenter;
using Infragistics.Windows.Editors;

namespace MyNamespace
{
public static class MaxLengthHelper
{

public static readonly DependencyProperty MaxLengthProperty = DependencyProperty.RegisterAttached(

"MaxLengthHelper",typeof(string), typeof(MaxLengthHelper),
new FrameworkPropertyMetadata(null, MaxLengthChanged));

private static void MaxLengthChanged(DependencyObject obj, DependencyPropertyChangedEventArgs e)
{
Field field = obj as Field;
if (field != null)
{
ValueConstraint vc = new ValueConstraint();
if(e.OldValue != null)
vc.MaxLength = (int)e.OldValue;

//Set the field'S MaxLength here
}
}
}
}

Parents
  • 16495
    Offline posted

    Hello Jan-Oliver,

     

    Thank you for your post.

     

    I have been looking into it and what I can suggest is to create styles for each value editor. You can take a look at the following forum thread, where the similar functionality was achieved:

     

    http://ko.infragistics.com/community/forums/t/31984.aspx

     

    I created short sample application based on your scenario to show you how you can implement the functionality that you are looking for.  Basically in the sample I created two  styles for XamTextEditor and XamNumericEditor. In the styles I created a setter for the ValueConstraint property and set some constraint. Than by using EditorStyle property of the Field class I applied these styles.

     

    Please let me know if you require any further assistance on the matter.

    SetMaxLengthIndividual.zip
Reply Children