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 } } }}
Hi Zhivko,
my account information should now be displayed correctly. I'm still interested in the solution for 14.1.
Best
Oliver
Hello Jan-Oliver,
Thank you for your post.
I have been looking into your issue. Currently you have a trial account. The support provided for trial accounts is for the latest version of our controls only. Currently this version is 15.1. More information about this you can find on the following link from our documentation:
http://ko.infragistics.com/support/support-policies.
If you would like to receive support for version 14.1 of our controls I could suggest contacting our Sales Department. The contacts for the Sales Department you can find on the following link from our web site:
http://ko.infragistics.com/about-us/contact-us.
Please do not hesitate to let me know if you have any further questions on this matter.
that's exactly what I was looking for. Unfortunately I'm using Infragistics Version 14.1 where field.ValueConstraint cannot be resolved.
The ValueConstraint seems to be hidden somewhere in Field.settings.editorstyle....
Would you mind, modifying your example for Version 14.1?
Thank you for your feedback.
I have been investigating further your issue and I created short sample application in order to be able to show you how you can implement the functionality that you are looking for. Basically in the sample application I crated attached property that set MaxLength property of ValueConstraint in Field.
Please let me know if you need any further assistance on the matter.
thanks for your effort! Unfortunately my code is very complex, so it would be very hard for me to extract a small and working example.
My problem with your solution is that I'm using my own TextBoxField with it's own TextBoxFieldSettings.
If I include your solution like in my code sample below, the DependencyProperty in my TextBoxFieldSettings does not work anymore (i.e. the ContextMenu does not show up):
<utils:TextBoxField Width="{StaticResource ColumnMediumWidth}"Label="Name" Name="Name"> <utils:TextBoxField.Settings> <utils:TextBoxFieldSettings> <utils:TextBoxFieldSettings.EditorStyle> <Style TargetType="{x:Type igWPF:XamTextEditor}"BasedOn="{StaticResource TextBoxCell}"> <Setter Property="ValueConstraint"> <Setter.Value> <igWPF:ValueConstraint MaxLength="50" /> </Setter.Value> </Setter> </Style> </utils:TextBoxFieldSettings.EditorStyle> </utils:TextBoxFieldSettings> </utils:TextBoxField.Settings> </utils:TextBoxField>
public class TextBoxFieldSettings : FieldSettings { private static readonly DependencyProperty ColorColumnProperty = DependencyProperty.Register("ColorColumn", typeof(string), typeof(TextBoxFieldSettings), new PropertyMetadata(null, ColorColumnChanged)); private static void ColorColumnChanged(DependencyObject d, DependencyPropertyChangedEventArgs e) { var fieldSettings = (TextBoxFieldSettings)d; if (e.NewValue != null) { var columnColorStyle = GridStyleManager.Instance.Styles["ColumnColorMenuItem"]; var item = new MenuItem() { CommandParameter = (string)e.NewValue, Style = columnColorStyle }; var menu = new ContextMenu(); menu.Items.Add(item); fieldSettings.LabelPresenterStyle = new Style(typeof(LabelPresenter)); fieldSettings.LabelPresenterStyle.Setters.Add(new Setter(LabelPresenter.ContextMenuProperty, menu)); } }
public string ColorColumn { get { return (string)GetValue(ColorColumnProperty); } set { SetValue(ColorColumnProperty, value); } }
public TextBoxFieldSettings() { this.CellHeight = 24; this.EditorStyle = GridStyleManager.Instance.Styles["TextBoxCell"]; this.CellValuePresenterStyle = GridStyleManager.Instance.Styles["CellNormalStyle"]; } }
Here is my TextBoxField (I do have more self-made fields):
public class TextBoxField : CustomField { public TextBoxField() { Settings = new TextBoxFieldSettings { CollapseWhenEmpty = false }; }
protected override void OnPropertyChanged(string propertyName) { if (propertyName == "Name") { if (!string.IsNullOrWhiteSpace(Name)) ((TextBoxFieldSettings)Settings).ColorColumn = Name; }
base.OnPropertyChanged(propertyName); } }