This is a migrated thread and some comments may be shown as answers.

DataFormDataField Length

4 Answers 127 Views
DataForm
This is a migrated thread and some comments may be shown as answers.
Bassam
Top achievements
Rank 1
Bassam asked on 13 Apr 2015, 05:46 PM

How to limit a TextBox that belongs to DataFormDataField to XXX number of characters?

Thanks,

<telerik:DataFormDataField  Grid.Row="1" Label="Name" DataMemberBinding="{Binding Name, Mode=TwoWay}" Description="Enter Name" />

4 Answers, 1 is accepted

Sort by
0
Dimitrina
Telerik team
answered on 14 Apr 2015, 07:37 AM
Hello,

DataFormDataField does not expose a property that limits the text length, however, you can customize the field's Content by setting the nested TextBox's MaxLength property. Please check the article on Customized Fields for some additional info on this matter.

Regards,
Dimitrina
Telerik
 

See What's Next in App Development. Register for TelerikNEXT.

 
0
Bassam
Top achievements
Rank 1
answered on 14 Apr 2015, 01:45 PM

Thanks.

 

It worked but dealing with the alignments didn't' make it viable. 

 

<telerik:DataFormDataField  Label="Bid Name" DataMemberBinding="{Binding Name, Mode=TwoWay}" Description="Enter Bid Name" />
      <telerik:DataFormDataField>
        <StackPanel Orientation="Horizontal">
          <TextBlock Text="Name"></TextBlock>
          <TextBox Text="{Binding SaveLocation}" MaxLength="50"></TextBox>
        </StackPanel>
      </telerik:DataFormDataField>

 

 

0
Bassam
Top achievements
Rank 1
answered on 14 Apr 2015, 02:06 PM

This is the solution that I came with: 

I created a Custom Field.  

 

public class DataFormTextField : DataFormDataField
  {
    private TextBox _textBox = null;
 
    public int MaxLength
    {
      get;
      set;
    }
 
    protected override System.Windows.DependencyProperty GetControlBindingProperty()
    {
      return TextBox.TextProperty;
    }
 
    protected override System.Windows.Controls.Control GetControl()
    {
      DependencyProperty dependencyProperty = this.GetControlBindingProperty();
      ContentControl content = new ContentControl();
      _textBox = new TextBox();
      if (this.MaxLength > 0)
      {
        _textBox.MaxLength = this.MaxLength;
      }
 
 
      if (this.DataMemberBinding != null)
      {
        var binding = this.DataMemberBinding;
        _textBox.SetBinding(dependencyProperty, binding);
      }
 
      content.Content = _textBox;
      return content;
    }
  }
0
Dimitrina
Telerik team
answered on 14 Apr 2015, 04:37 PM
Hi,

Thank you for sharing the solution you implemented with the community. 

Regards,
Dimitrina
Telerik
 

See What's Next in App Development. Register for TelerikNEXT.

 
Tags
DataForm
Asked by
Bassam
Top achievements
Rank 1
Answers by
Dimitrina
Telerik team
Bassam
Top achievements
Rank 1
Share this question
or