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

7 posts, 0 answers
  1. Zhang
    Zhang avatar
    13 posts
    Member since:
    Oct 2013

    Posted 14 Jan 2014 Link to this post

    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!!
  2. Zhang
    Zhang avatar
    13 posts
    Member since:
    Oct 2013

    Posted 15 Jan 2014 Link to this post

    It's OK now, I should use DataFormDataField.Content rather than DataFormDataField.ContentTemplate.
  3. Anton
    Anton avatar
    3 posts
    Member since:
    Feb 2017

    Posted 01 Aug Link to this post

    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>

     

     

  4. Anton
    Anton avatar
    3 posts
    Member since:
    Feb 2017

    Posted 01 Aug in reply to Anton Link to this post

    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}" />
  5. Yoan
    Admin
    Yoan avatar
    1124 posts

    Posted 03 Aug Link to this post

    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 allow you to write beautiful native mobile apps using a single shared C# codebase.
  6. Anton
    Anton avatar
    3 posts
    Member since:
    Feb 2017

    Posted 03 Aug in reply to Yoan Link to this post

    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.

  7. Yoan
    Admin
    Yoan avatar
    1124 posts

    Posted 08 Aug Link to this post

    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.
Back to Top