Setting template for ValidationSummary

2 posts, 0 answers
  1. Jeff
    Jeff avatar
    64 posts
    Member since:
    Dec 2011

    Posted 06 Feb 2013 Link to this post

    In an earlier thread, Ivan wrote:

        "You can create a new ControlTemplate for DataFormValidationSummary and set it through RadDataForm's ValidationSummaryStyle property. In this ControlTemplate you can set a new ItemTemplate to the ItemsControl placed in the summary. Please, use the latest internal build, if possible, as we have fixed a related issue there."

    I'm trying to do this, but I'm only about half-way there.

    I'm setting ValidationSummaryStyle on the RadDataForm:
            ValidationSummaryStyle="{StaticResource validationSummaryStyle}"
    And in Resources I'm defining the style that sets DataFormValidationSummary.Template, and the ControlTemplate that it is being set to.
        <ControlTemplate x:Key="validationSummaryTemplate">
        <Style TargetType="telerikDataForm:DataFormValidationSummary" x:Key="validationSummaryStyle">
            <Setter Property="Template" Value="{StaticResource validationSummaryTemplate}" />
    And this works, so far is it goes.  I see the string "Foo" in the appropriate spot.

    But I'm unclear as to what "set a new ItemTemplate to the ItemsControl placed in the summary" is supposed to mean. 
  2. Ivan Ivanov
    Ivan Ivanov avatar
    1218 posts

    Posted 11 Feb 2013 Link to this post


    I will try to explain my previous point on this. Here is the default template for the validation summary is OfficeBlack:

    <ControlTemplate x:Key="DataFormValidationSummaryTemplate" TargetType="dataForm:DataFormValidationSummary">
           <Border BorderThickness="0,1,0,0" BorderBrush="{StaticResource ValidationSummary_BorderBrush}" Background="{StaticResource ValidationSummary_Background}" Height="{TemplateBinding Height}">
               <ItemsControl IsTabStop="False" ItemsSource="{Binding RelativeSource={RelativeSource TemplatedParent}, Path=Errors}" >
                       <Style TargetType="ItemsControl">
                           <Setter Property="Template">
                                       <ScrollViewer IsTabStop="False" Name="ScrollViewer" BorderBrush="{StaticResource ControlOuterBorder}" BorderThickness="0,0,0,1" ScrollViewer.VerticalScrollBarVisibility="Auto" ScrollViewer.HorizontalScrollBarVisibility="Auto" telerik:StyleManager.Theme="{StaticResource Theme}">
                           <Setter Property="ItemTemplate">
                                       <StackPanel Orientation="Horizontal">
                                           <TextBlock Foreground="{StaticResource ValidationSummary_Foreground}" Margin="5,5,0,5" FontWeight="Bold" Text="{Binding SourceFieldDisplayName}"/>
                                           <TextBlock Foreground="{StaticResource ValidationSummary_Foreground}" FontWeight="Bold"  Text=":" Margin="0,5,0,0" />
                                           <TextBlock Margin="5,5,0,5" Text="{Binding ErrorContent}" />
                           <Setter Property="MaxHeight" Value="75"/>
    As you can see the errors are listed in a scrollable ItemsControl, which has a customized ItemTemplate that consists of 3 textblocks. You can modify this, in order to make it fit to your needs.Greetings,
    Ivan Ivanov
    the Telerik team

    Explore the entire Telerik portfolio by downloading Telerik DevCraft Ultimate.

Back to Top