DataFormDataField Length

5 posts, 0 answers
  1. Bassam
    Bassam avatar
    8 posts
    Member since:
    Mar 2015

    Posted 13 Apr 2015 Link to this post

    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" />

  2. Dimitrina
    Admin
    Dimitrina avatar
    3769 posts

    Posted 14 Apr 2015 Link to this post

    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.

     
  3. UI for WPF is Visual Studio 2017 Ready
  4. Bassam
    Bassam avatar
    8 posts
    Member since:
    Mar 2015

    Posted 14 Apr 2015 in reply to Dimitrina Link to this post

    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>

     

     

  5. Bassam
    Bassam avatar
    8 posts
    Member since:
    Mar 2015

    Posted 14 Apr 2015 Link to this post

    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;
        }
      }
  6. Dimitrina
    Admin
    Dimitrina avatar
    3769 posts

    Posted 14 Apr 2015 Link to this post

    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.

     
Back to Top
UI for WPF is Visual Studio 2017 Ready