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

DataFormDataField.ContentTemplate doesn't work in your latest versions, is it a bug?

6 Answers 80 Views
DataForm
This is a migrated thread and some comments may be shown as answers.
Zhang
Top achievements
Rank 1
Zhang asked on 14 Jan 2014, 10:34 AM
I found that DataFormDataField.ContentTemplate doesn't work since version "RadControls for WPF Q2 2013",  actually i only have the latest 3 versions. I've tried each one, all the same, just display the default textbox. My code is simple, just copy from your online documentation, as below:
     <Grid x:Name="LayoutRoot" Background="White">
            <Grid.Resources>
                <DataTemplate x:Key="MyTemplate">
                    <StackPanel Orientation="Horizontal" >
                        <telerik:DataFormDataField>
                            <telerik:DataFormDataField.LabelTemplate>
                                <DataTemplate>
                                    <Label Foreground="Orange">Title:</Label>
                                </DataTemplate>
                            </telerik:DataFormDataField.LabelTemplate>
                            <telerik:DataFormDataField.ContentTemplate>
                                <DataTemplate>
                                    <StackPanel Orientation="Horizontal">
                                        <TextBox Text="25" Margin="0,0,10,0" />
                                        <TextBlock Text="years" Foreground="Green" VerticalAlignment="Bottom" />
                                    </StackPanel>
                                </DataTemplate>
                            </telerik:DataFormDataField.ContentTemplate>
                        </telerik:DataFormDataField>
                    </StackPanel>
                </DataTemplate>
            </Grid.Resources>
            <telerik:RadDataForm x:Name="DataForm1"
                           AutoGenerateFields="False" 
                           ReadOnlyTemplate="{StaticResource MyTemplate}">
            </telerik:RadDataForm>
        </Grid>

MOST URGENT, PLEASE ANSWER IT QUICKLY, THANK YOU!!

6 Answers, 1 is accepted

Sort by
0
Zhang
Top achievements
Rank 1
answered on 15 Jan 2014, 08:37 AM
It's OK now, I should use DataFormDataField.Content rather than DataFormDataField.ContentTemplate.
0
Anton
Top achievements
Rank 1
answered on 01 Aug 2017, 07:38 AM

It's not OK. I want to set ContentTemplate in style. It does not work.

Ivan Ivanov wrote that it's not supported in Telerik for WPF: http://www.telerik.com/forums/dataformdatafield-contenttemplate-example#DLMthmV4h0GQbxxhYd5YFg

Then he posted example with ContentTemplate, but it does not work actually: http://www.telerik.com/forums/dataformdatafield-contenttemplate-example#8c2eBHHE70eJuh-NNpSo7g

 

<DataTemplate x:Key="DTempate">
    <StackPanel>
        <telerik:DataFormDataField DataMemberBinding="{Binding Name}" Label="Name1">
            <telerik:DataFormDataField.ContentTemplate>
                <DataTemplate>
                    <Button Background="Yellow" Content="{Binding Name}" />
                </DataTemplate>
            </telerik:DataFormDataField.ContentTemplate>
        </telerik:DataFormDataField>
        <telerik:DataFormDataField DataMemberBinding="{Binding Name}" Label="Name2">
            <Button Background="Yellow" Content="{Binding Name}" />
        </telerik:DataFormDataField>
    </StackPanel>
</DataTemplate>

 

 

0
Anton
Top achievements
Rank 1
answered on 01 Aug 2017, 07:44 AM

The style I want to create:

<Style x:Key="CustomerComboBoxFieldStyle" TargetType="{x:Type telerik:DataFormComboBoxField}" BasedOn="{StaticResource DataFormDataFieldStyle}">
    <Setter Property="ContentTemplate">
        <Setter.Value>
            <DataTemplate>
                <telerik:RadComboBox
                        ItemsSource="{Binding ItemsSource, RelativeSource={RelativeSource Mode=FindAncestor, AncestorType={x:Type telerik:DataFormComboBoxField}}}"
                        Style="{StaticResource CustomerComboBoxStyle}" />
            </DataTemplate>
        </Setter.Value>
    </Setter>
</Style>

 

<telerik:DataFormComboBoxField Label="Customer" ItemsSource="{Binding Customers}" Style="{StaticResource CustomerComboBoxFieldStyle}" />
0
Yoan
Telerik team
answered on 03 Aug 2017, 02:52 PM
Hi Anton,

Indeed, DataFormDataFiled respects the Content property only. You can try to modify your style to set the Content property instead. Can you give it a try and confirm whether it is a viable option for you?

Regards,
Yoan
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 you to write beautiful native mobile apps using a single shared C# codebase.
0
Anton
Top achievements
Rank 1
answered on 04 Aug 2017, 03:23 AM

Hi Yoan,

I tried, it works incorrectly. Only one control in application will receive the content. It's expected behavior, it's wrong to set Content in WPF style.

0
Yoan
Telerik team
answered on 08 Aug 2017, 11:48 AM
Hello Anton,

Indeed you are right. This is why we have applied a fix for this issue. The fix is expected to be released with next internal build (next week).

Regards,
Yoan
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
Zhang
Top achievements
Rank 1
Answers by
Zhang
Top achievements
Rank 1
Anton
Top achievements
Rank 1
Yoan
Telerik team
Share this question
or