Content alignment in DataFormDataField

2 posts, 0 answers
  1. Barry
    Barry avatar
    29 posts
    Member since:
    May 2016

    Posted 25 Aug Link to this post

    I'm trying to get the label to align left, and the text box to align left, in their respective columns. Can't make it happen. Both the label and the textbox seem to move to the same column, and have a mind of their own.

    Here's the set-up:

     <Grid ShowGridLines="True" x:Name="DetailsTemplateEdit_Section_Main_Controls" HorizontalAlignment="Stretch" Background="White" MaxWidth="{Binding ActualWidth, Mode=OneWay, RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type Border}}}">

                            <Grid.RowDefinitions>
                                <RowDefinition Height="auto" />
                                <RowDefinition Height="auto"/>
                                <RowDefinition Height="auto"/>
                            </Grid.RowDefinitions>

                            <Grid.ColumnDefinitions>
                                <ColumnDefinition MinWidth="150" MaxWidth="150"/>
                                <ColumnDefinition Width="2*"/>
                                <ColumnDefinition Width="Auto" />
                            </Grid.ColumnDefinitions>

                            <telerik:DataFormDataField Grid.Row="0" Grid.Column="0" 
                                               Label="{x:Static properties:Resources.Compliance_Label_Name}" 
                                               DataMemberBinding="{Binding Name, Mode=TwoWay}" Template="{DynamicResource CustomDataFormDataFieldControlTemplate}">
                                  <TextBox Grid.Row="0" Grid.Column="1" Text="{Binding Name, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged, ValidatesOnDataErrors=True, NotifyOnValidationError=True, ValidatesOnExceptions=True}" 
                                  IsEnabled="{Binding CanBeDeleted}" x:Name="txt_name" HorizontalAlignment="Left"    
                                      Style="{StaticResource WaterMarkTextBox}" THOR:WaterMarkTextHelper.WatermarkText="{x:Static properties:Resources.Compliance_Label_Name}"
                                      MaxLength="50" ToolTip="{x:Static properties:Resources.ComplianceSetup_tooltip_name}" />
                            </telerik:DataFormDataField>

     

    So, based on an example I saw the grid should have three columns, and I tried to set the label to be in column 1, and the text box in column 2, and I need both to align to the left within their columns.

    Hints ?

  2. Barry
    Barry avatar
    29 posts
    Member since:
    May 2016

    Posted 25 Aug in reply to Barry Link to this post

    Actually, I found if I decouple the label from the DataFormDataField I could put it in column=0, and then the DataFormDataField in column=1  ...and set HorizontalContentAlignment="Left" for both and I was good.

     

                            <Label Width="150" HorizontalAlignment="Left" Content="{x:Static properties:Resources.Compliance_Label_Name}" Grid.Row="0" Grid.Column="0" />
                            <telerik:DataFormDataField Grid.Row="0" Grid.Column="1" HorizontalAlignment="Left" 
                                               DataMemberBinding="{Binding Name, Mode=TwoWay}" Template="{DynamicResource CustomDataFormDataFieldControlTemplate}">
                                    <TextBox Text="{Binding Name, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged, ValidatesOnDataErrors=True, NotifyOnValidationError=True, ValidatesOnExceptions=True}" 
                                      IsEnabled="{Binding CanBeDeleted}" x:Name="txt_name" 
                                      Style="{StaticResource WaterMarkTextBox}" THOR:WaterMarkTextHelper.WatermarkText="{x:Static properties:Resources.Compliance_Label_Name}"
                                      MaxLength="50" Width="250" Margin="-15,0,0,0" ToolTip="{x:Static properties:Resources.ComplianceSetup_tooltip_name}" />
                            </telerik:DataFormDataField>

  3. UI for WPF is Visual Studio 2017 Ready
Back to Top