Multiline DataFormDataField

12 posts, 1 answers
  1. Brian
    Brian avatar
    58 posts
    Member since:
    Jul 2011

    Posted 28 Sep 2011 Link to this post

    How do I create a multi-line DataFormDataField?  The closest I have gotten is this:

    <telerik:DataFormDataField Name="DescriptionField" Label="Description:" MinHeight="100" LabelPosition="Above" HorizontalAlignment="Stretch" VerticalAlignment="Top" VerticalContentAlignment="Stretch" />

    This creates a textbox that appears to be multi-line, but it looks like the label is given the same MinHeight value as the textbox, even though the LabelPosition is Above, which causes a blank space between the label and the textbox equal to the height of the textbox (roughly).  Is there any way to just resize the height of the textbox?

    If I change the LabelPosition to "Beside", the behavior is even stranger, as I get a blank space above the textbox that is roughly equal to its height.

    Has anyone been successful in making a multi-line textbox from the DataFormDataField?
  2. Ivan Ivanov
    Admin
    Ivan Ivanov avatar
    1127 posts

    Posted 29 Sep 2011 Link to this post

    Hi Brian,

    I have prepared an example project that illustrates a possible approach to this scenario. Please, refer to the attachment and inform us whether this solution meets your requirements.

    Regards,
    Ivan Ivanov
    the Telerik team
    Explore the entire Telerik portfolio by downloading the Ultimate Collection trial package. Get it now >>
  3. DevCraft banner
  4. Brian
    Brian avatar
    58 posts
    Member since:
    Jul 2011

    Posted 29 Sep 2011 Link to this post

    Ivan,
    Thank you for responding.  While the textbox in your example grows to fix the text as necessary, I would like the box to be at least 2 lines tall even when empty so that it is obvious that you can enter long text in it.  Is this possible?

    Also, it would be nice if it were possible to enter a "return" in the textbox, so that it is truly multi-line.  I tried both pressing enter and shift+enter in your example and was unable to insert a newline.
  5. Ivan Ivanov
    Admin
    Ivan Ivanov avatar
    1127 posts

    Posted 29 Sep 2011 Link to this post

    Hello Brian,

    In order to achieve this, try changing the respective DataFormDataField's ContentTemplate with this one:
    <DataTemplate x:Key="MultiLineTemplate">
        <TextBox TextWrapping="Wrap" Text="{Binding Description}" AcceptsReturn="True" MinHeight="40"/> 
    </DataTemplate>


    Greetings,
    Ivan Ivanov
    the Telerik team
    Explore the entire Telerik portfolio by downloading the Ultimate Collection trial package. Get it now >>
  6. Brian
    Brian avatar
    58 posts
    Member since:
    Jul 2011

    Posted 29 Sep 2011 Link to this post

    Ivan,
    I replaced the DataTemplate in your earlier solution with the one in your latest message, but it didn't seem to have any effect.  The textbox still shrinks if I remove enough text and I still cannot insert a newline via pressing Enter or Shift+Enter.
  7. Ivan Ivanov
    Admin
    Ivan Ivanov avatar
    1127 posts

    Posted 04 Oct 2011 Link to this post

    Hello Brian,

    Setting AcceptsReturn to "True" enables the TextBox to move its input cursor to the next line when the "Enter" key is pressed, You should not have any problems with this. Would you please double check it? As for the measurement issue, it is related exclusively to Silverlight's Layout mechanism. TextBox's Height value is either a fixed value, or "Auto". If you use the latter one, the TextBox will ask its parent panel for as much space as it needs to display its text. Consequently, in this scenario, it is totally expected for the TextBox to reduce its height when text is removed. You may try hardcoding a value if such behavior is acceptable in your scenario.

    Greetings,
    Ivan Ivanov
    the Telerik team
    Explore the entire Telerik portfolio by downloading the Ultimate Collection trial package. Get it now >>
  8. Brian
    Brian avatar
    58 posts
    Member since:
    Jul 2011

    Posted 04 Oct 2011 Link to this post

    Ivan,
    I just double-checked, and I am unable to enter a newline in the TextBox.  Here is what my MainPage.xaml currently looks like:

    <UserControl x:Class="RadGridView_SL4_AR_236.MainPage"
                 xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
                 xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
                 xmlns:telerik="http://schemas.telerik.com/2008/xaml/presentation"
                 xmlns:my="clr-namespace:RadGridView_SL4_AR_236"
                 mc:Ignorable="d" d:DesignHeight="700" d:DesignWidth="700">
        <UserControl.Resources>
            <my:MyViewModel x:Key="MyViewModel"/>
            <DataTemplate x:Key="MultiLineTemplate">
                <TextBox TextWrapping="Wrap" Text="{Binding Description}" AcceptsReturn="True" MinHeight="40"/>
            </DataTemplate>
        </UserControl.Resources>
        <Grid x:Name="LayoutRoot" 
              Background="White" 
              DataContext="{StaticResource MyViewModel}">      
            <telerik:RadDataForm Name="clubsForm" 
                                 AutoGeneratingField="clubsForm_AutoGeneratingField"                            
                                 ItemsSource="{Binding Clubs}"                                        
                                 Margin="5">
            </telerik:RadDataForm>       
        </Grid>
    </UserControl>
  9. Answer
    Ivan Ivanov
    Admin
    Ivan Ivanov avatar
    1127 posts

    Posted 09 Oct 2011 Link to this post

    Hello Brian,

    I have updated my initial project, utilizing the DataTemplate from the code snippet you have provided and it is working fine on my side. I am attaching it for your reference.

    Greetings,
    Ivan Ivanov
    the Telerik team
    Explore the entire Telerik portfolio by downloading the Ultimate Collection trial package. Get it now >>
  10. Brian
    Brian avatar
    58 posts
    Member since:
    Jul 2011

    Posted 10 Oct 2011 Link to this post

    Ivan,
        Thanks, that one works for me as well.  Strangely, if I do a diff on that project vs. the one that doesn't work for me, the only source file that looks different is the .csproj.  I noticed that the Telerik.Windows.Controls.Data.dll that you are using is version 2011.2.920.1040, while the version I am referencing in the solution that doesn't work is version 2011.1.0419.1040.  Is it possible that this solution will not work with the older version of the Telerik controls that I am using?
  11. Ivan Ivanov
    Admin
    Ivan Ivanov avatar
    1127 posts

    Posted 11 Oct 2011 Link to this post

    Hi Brian,

    I have referenced 2011.1.419 binaries of RadControls, but I have not noticed any change in this behavior.
    However, if the issue persists you might try isolating it in a separate project and send it  to us. We will do our best to pinpoint this problem's source. Meanwhile, you may have a look at the attached project and tell us whether there are any related differences with your solution.

    Best wishes,
    Ivan Ivanov
    the Telerik team
    Explore the entire Telerik portfolio by downloading the Ultimate Collection trial package. Get it now >>
  12. Anna Katrina
    Anna Katrina avatar
    9 posts
    Member since:
    Feb 2013

    Posted 14 Jul 2014 Link to this post

    HI,

    Do you know how I can place the dataForm:Datafield label above textbox, seems to me that the only way to display label is to be display it beside of the textbox (left side). Are there ways to be able to place it wherever i want?

    Thanks and Regards,
    Anna
  13. Ivan Ivanov
    Admin
    Ivan Ivanov avatar
    1127 posts

    Posted 16 Jul 2014 Link to this post

    Hello,

    You can achieve this by editing DataFormDataField's ControlTemplate. If you are using NoXAML assemblies and have the controls' styles and templates as separate resource files, you can apply the changes directly there. On the other hand, if you are using our standard assemblies, you can use Expression Blend, or VS Designer to extract the template and modify it.

    Regards,
    Ivan Ivanov
    Telerik
     
    Check out Telerik Analytics, the service which allows developers to discover app usage patterns, analyze user data, log exceptions, solve problems and profile application performance at run time. Watch the videos and start improving your app based on facts, not hunches.
     
Back to Top
DevCraft banner