ren
ren

Reputation: 3993

silverlight 4 datagrid: how to put custom message instead of "Error" in validation panel

So, in datagrid or dataform if there are validation errors we have white Error word upon red ribbon.

How do I put my message there?

EDIT: Clarification: I'm happy with everything. The only thing I want is to translate "ERROR" word displayed in datagrid validation panel into other language.

Upvotes: 0

Views: 1251

Answers (2)

ren
ren

Reputation: 3993

ok, I managed to do this by adding this to my custom styles resource dictionary:

' Style TargetType="dataInput:ValidationSummary">

    <Setter Property="HeaderTemplate">
        <Setter.Value>
            <DataTemplate>
                <Border Background="#FFDC020D" CornerRadius="2" x:Name="Header" Margin="-1,-1,-1,0">
                    <StackPanel Margin="6,2,6,4" Orientation="Horizontal" VerticalAlignment="Top">
                        <Grid Height="13" Width="13">
                            <Ellipse Margin="0" RenderTransformOrigin="0.5,0.5" >
                                <Ellipse.Stroke>
                                    <LinearGradientBrush StartPoint="0.505,0.65" EndPoint="0.5,0.058">
                                        <GradientStop Color="#FFCA000C" Offset="0"/>
                                        <GradientStop Color="#FFFF9298" Offset="0.991"/>
                                    </LinearGradientBrush>
                                </Ellipse.Stroke>
                                <Ellipse.Fill>
                                    <LinearGradientBrush StartPoint="0.5,0" EndPoint="0.5,1">
                                        <GradientStop Color="#FFFFFFFF" Offset="0"/>
                                        <GradientStop Color="#FFFDC8C8" Offset="1"/>
                                    </LinearGradientBrush>
                                </Ellipse.Fill>
                            </Ellipse>
                            <Path Fill="#DDD43940" Data="M5.5,2.5 L7.5,2.5 L7.5,8 L5.5,8 M5.5,9.5 L7.5,9.5 L7.5,10.5 L5.5,10.5"/>
                        </Grid>
                        <TextBlock Padding="4,1,0,0" Text="CUSTOM MESSAGE" Foreground="#FFFFFFFF" FontWeight="Bold"/>
                    </StackPanel>
                </Border>
            </DataTemplate>
        </Setter.Value>
    </Setter>
</Style>

where dataInput is xmlns:dataInput="clr-namespace:System.Windows.Controls;assembly=System.Windows.Controls.Data.Input"

these styles and templates are really lengthy

Upvotes: 1

Keith Adler
Keith Adler

Reputation: 21178

Because Silverlight is big on separation of concerns this really should be driven by validation in your middle tier using Data Annotation Validators and the INotifyDataErrorInfo. A good approach is to rely on WCF RIA Services and what it provides. See this article: http://www.silverlightshow.net/items/WCF-RIA-Services-Part-6-Validating-Data.aspx

You could create your own error control to display the errors as well, but the pattern of putting business rules enforcement purely at the client is not ideal. WCF RIA Services allows business rules coded at the middle tier to flow effortlessly into the client side code. One problem with grids however is the fact that you are never really editing more than one row at a time so display multirow errors is not possible.

Upvotes: 1

Related Questions