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

Setting template for ValidationSummary

1 Answer 199 Views
DataForm
This is a migrated thread and some comments may be shown as answers.
Jeff
Top achievements
Rank 1
Jeff asked on 06 Feb 2013, 08:39 PM
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:
<telerik: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.
<UserControl.Resources>
 
    <ControlTemplate x:Key="validationSummaryTemplate">
        <Label>Foo</Label>
    </ControlTemplate>
 
    <Style TargetType="telerikDataForm:DataFormValidationSummary" x:Key="validationSummaryStyle">
        <Setter Property="Template" Value="{StaticResource validationSummaryTemplate}" />
    </Style>
</UserControl.Resources>
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. 

1 Answer, 1 is accepted

Sort by
0
Ivan Ivanov
Telerik team
answered on 11 Feb 2013, 03:55 PM
Hi,

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}" >
               <ItemsControl.Style>
                   <Style TargetType="ItemsControl">
                       <Setter Property="Template">
                           <Setter.Value>
                               <ControlTemplate>
                                   <ScrollViewer IsTabStop="False" Name="ScrollViewer" BorderBrush="{StaticResource ControlOuterBorder}" BorderThickness="0,0,0,1" ScrollViewer.VerticalScrollBarVisibility="Auto" ScrollViewer.HorizontalScrollBarVisibility="Auto" telerik:StyleManager.Theme="{StaticResource Theme}">
                                       <ItemsPresenter/>
                                   </ScrollViewer>
                               </ControlTemplate>
                           </Setter.Value>
                       </Setter>
                       <Setter Property="ItemTemplate">
                           <Setter.Value>
                               <DataTemplate>
                                   <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}" />
                                   </StackPanel>
                               </DataTemplate>
                           </Setter.Value>
                       </Setter>
                       <Setter Property="MaxHeight" Value="75"/>
                   </Style>
               </ItemsControl.Style>
           </ItemsControl>
       </Border>
   </ControlTemplate>
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.

Tags
DataForm
Asked by
Jeff
Top achievements
Rank 1
Answers by
Ivan Ivanov
Telerik team
Share this question
or