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

Is it possible to set the Datafield Label Horizontal Position for Auto Generated Fields.

3 Answers 124 Views
DataForm
This is a migrated thread and some comments may be shown as answers.
David
Top achievements
Rank 1
David asked on 11 Oct 2017, 03:35 PM

Is it possible to set the Datafield labels horizontal position when the columns are auto generated in code?  The look of left justified labels is not the best look for my customers application.  It seems odd that there is not simple property that could be set to achieve this in the AutoGeneratingField event.

Some labels are large and some are small and make it difficult on the eyes to follow a small label so far from it's associated control.

Thank you...

3 Answers, 1 is accepted

Sort by
0
Stefan
Telerik team
answered on 16 Oct 2017, 12:44 PM
Hello David,

In order to alter the default visual representation of the labels of the control, you can edit the template of the DataFormDataField element. Within it, there is a ContentControl with x:Name="PART_Label". You can set its HorizontalAlignment property as per your requirements.
<ControlTemplate x:Key="DataFormDataFieldTemplate" TargetType="controls:DataFormDataField">
        <Border x:Name="PART_RootElement" Background="{TemplateBinding Background}" BorderBrush="{TemplateBinding BorderBrush}" BorderThickness="{TemplateBinding BorderThickness}">
            <Grid x:Name="PART_DataFormDataFieldGrid" Margin="{TemplateBinding Padding}">
                <Grid.ColumnDefinitions>
                    <ColumnDefinition Width="*"/>
                    <ColumnDefinition Width="2*"/>
                    <ColumnDefinition Width="24"/>
                </Grid.ColumnDefinitions>
                <Grid.RowDefinitions>
                    <RowDefinition/>
                    <RowDefinition/>
                </Grid.RowDefinitions>
                <ContentControl x:Name="PART_Label"
                        IsTabStop="False"
                        Content="{TemplateBinding Label}"
                        Foreground="{TemplateBinding Foreground}"
                                HorizontalAlignment="Center"
                        Margin="5,0"
                        ContentTemplate="{TemplateBinding LabelTemplate}"/>
                <ContentPresenter
                        Grid.Row="1"
                        x:Name="PART_ContentPresenter"
                        Grid.Column="1"
                        Content="{TemplateBinding Content}"
                        VerticalAlignment="{TemplateBinding VerticalContentAlignment}"
                        HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}"
                        Margin="5,0"/>
                <Grid
                        Grid.Row="1"
                        x:Name="DescriptionIcon"
                        Visibility="{Binding Description, Converter={StaticResource DescriptionVisibilityConverter},RelativeSource={RelativeSource TemplatedParent}}"
                        Grid.Column="2"
                        Width="16"
                        Height="16"
                        Margin="4,0">
                    <ToolTipService.ToolTip>
                        <ToolTip Content="{TemplateBinding Description}"/>
                    </ToolTipService.ToolTip>
                    <Ellipse>
                        <Ellipse.Fill>
                            <LinearGradientBrush EndPoint="0.5,1" StartPoint="0.5,0">
                                <GradientStop Color="#FF68A2DB" Offset="0"/>
                                <GradientStop Color="#FF2C6CC0" Offset="1"/>
                            </LinearGradientBrush>
                        </Ellipse.Fill>
                    </Ellipse>
                    <Ellipse Margin="1">
                        <Ellipse.Stroke>
                            <LinearGradientBrush EndPoint="0.5,1" StartPoint="0.5,0">
                                <GradientStop Color="#FFA2C2E6" Offset="0"/>
                                <GradientStop Color="#FF558DD3" Offset="1"/>
                            </LinearGradientBrush>
                        </Ellipse.Stroke>
                    </Ellipse>
                    <Path
                            Data="M3.3820179,7.7910166 C3.9343026,7.7910166 4.3820181,8.2387314 4.3820181,8.7910166 C4.3820181,9.3433018 3.9343026,9.7910166 3.3820179,9.7910166 C2.8297331,9.7910166 2.3820179,9.3433018 2.3820179,8.7910166 C2.3820179,8.2387314 2.8297331,7.7910166 3.3820179,7.7910166 z M3.4866922,0 C4.5602031,0 5.4141321,0.28477871 6.0484791,0.8543362 C6.682826,1.423894 6.9999995,2.0868769 7.0000005,2.8432846 C6.9999995,3.2620106 6.8835549,3.6582246 6.6506658,4.0319262 C6.4177752,4.4056277 5.9253707,4.9212208 5.1568441,5.55825 C4.366394,6.2134514 4.350769,6.7758508 4.350769,6.7758508 C4.350769,6.7758508 2.382019,6.776 2.382019,6.776 C2.382019,6.776 2.460144,5.5571427 3.9524715,4.4033766 C4.511868,3.97089 4.8241448,3.6582246 4.9306087,3.5186491 C5.0947404,3.2980301 5.1768064,3.0548987 5.1768064,2.7892554 C5.1768064,2.4200568 5.0315275,2.103761 4.7409697,1.8403683 C4.4504123,1.5769768 4.0589356,1.4452807 3.56654,1.4452801 C3.0918882,1.4452807 2.6948667,1.5826048 2.3754754,1.8572525 C2.0560837,2.1319013 1.836502,2.5506272 1.7167301,3.1134305 L0,2.8973138 C0.048795935,2.0913794 0.38704056,1.40701 1.0147338,0.84420568 C1.6424271,0.28140187 2.4664133,0 3.4866922,0 z"
                            Margin="4.618,3.209,4.382,3"
                            RenderTransformOrigin="0.499999968851403,0.346031483547006"
                            Stretch="Fill">
                        <Path.Fill>
                            <SolidColorBrush Color="White">
                                <SolidColorBrush.RelativeTransform>
                                    <MatrixTransform Matrix="Identity"/>
                                </SolidColorBrush.RelativeTransform>
                                <SolidColorBrush.Transform>
                                    <MatrixTransform Matrix="Identity"/>
                                </SolidColorBrush.Transform>
                            </SolidColorBrush>
                        </Path.Fill>
                        <Path.RenderTransform>
                            <TransformGroup>
                                <ScaleTransform/>
                                <SkewTransform/>
                                <RotateTransform/>
                                <TranslateTransform/>
                            </TransformGroup>
                        </Path.RenderTransform>
                    </Path>
                </Grid>
            </Grid>
        </Border>
    </ControlTemplate>

Can you please give the suggestion a try? Does it correspond to your requirements?

Regards,
Stefan
Progress Telerik
Want to extend the target reach of your WPF applications, leveraging iOS, Android, and UWP? Try UI for Xamarin, a suite of polished and feature-rich components for the Xamarin framework, which allow you to write beautiful native mobile apps using a single shared C# codebase.
0
David
Top achievements
Rank 1
answered on 17 Oct 2017, 02:41 PM

Yes this worked. I had to copy the entire dictionary for that control in to my project however.  Is that how I am supposed to do it?  Then make modifications to it? 

So I copied Telerik.Windows.Controls.Data from the theme I wanted to use

After compiling I have no errors which is good. And I can execute the program and it works as expected. 

However after I run program in debug, errors start showing up everywhere I use the user control and do not go away until I recompile.

SeverityCodeDescriptionProjectFileLineSuppression State
ErrorCannot locate resource 'telerik.windows.controls.data.xaml'.BurnsMainD:\SourceCode\Burns\BurnsMain\Windows\frmCustomer.xaml177

 

0
Stefan
Telerik team
answered on 20 Oct 2017, 08:12 AM
Hello David,

I am glad that the proposed solution worked for you.

As to the error you are experiencing, it can be due to assemblies version mismatch. In such case please, do the following steps:

- Ensure that all referenced assemblies are of the same version.

- Close all instances of Visual Studio

- Manually delete the bin and obj folders of the application. Then clean and rebuild it.

Is the problem still reproduced?

Regards,
Stefan
Progress Telerik
Want to extend the target reach of your WPF applications, leveraging iOS, Android, and UWP? Try UI for Xamarin, a suite of polished and feature-rich components for the Xamarin framework, which allow you to write beautiful native mobile apps using a single shared C# codebase.
Tags
DataForm
Asked by
David
Top achievements
Rank 1
Answers by
Stefan
Telerik team
David
Top achievements
Rank 1
Share this question
or