Hi,
i have spent the last two days two find out how the validation works in the dataform. My DAL uses Entity Framework 4.1 with auto generated POCO Entities (in a seperate Assembly).
I'm working with MVVM and have UserControls for my views. One UserControl has a RadDataFrom with customized fields. The currentItem is bound to a an instance of my POCO Entities. Now i'd like to use DataAnnotations in the entities for my validatioin. But the error are not displayed in the dataform. I don't know what i'm doing wrong, can you please help me?
Here is the UserControl containing the dataform and the corresponding POCO:
i have spent the last two days two find out how the validation works in the dataform. My DAL uses Entity Framework 4.1 with auto generated POCO Entities (in a seperate Assembly).
I'm working with MVVM and have UserControls for my views. One UserControl has a RadDataFrom with customized fields. The currentItem is bound to a an instance of my POCO Entities. Now i'd like to use DataAnnotations in the entities for my validatioin. But the error are not displayed in the dataform. I don't know what i'm doing wrong, can you please help me?
Here is the UserControl containing the dataform and the corresponding POCO:
<
UserControl
xmlns:telerik
=
"http://schemas.telerik.com/2008/xaml/presentation"
x:Class
=
"MiexProto.Views.EmployeeFormView"
mc:Ignorable
=
"d"
x:Name
=
"me"
d:DesignHeight
=
"300"
d:DesignWidth
=
"300"
>
<
UserControl.Resources
>
<
DataTemplate
x:Key
=
"EmployeeTemplate"
>
<
Grid
>
<
Grid.ColumnDefinitions
>
<
ColumnDefinition
/>
<
ColumnDefinition
/>
<
ColumnDefinition
/>
</
Grid.ColumnDefinitions
>
<
Grid.RowDefinitions
>
<
RowDefinition
/>
<
RowDefinition
/>
<
RowDefinition
/>
</
Grid.RowDefinitions
>
<
StackPanel
Orientation
=
"Horizontal"
Grid.Row
=
"0"
Grid.Column
=
"0"
>
<
Label
Content
=
"Anrede"
/>
<
telerik:DataFormComboBoxField
Height
=
"auto"
DataMemberBinding
=
"{Binding AnredeId, Mode=TwoWay, NotifyOnValidationError=True, ValidatesOnExceptions=True}"
SelectedValuePath
=
"AnredeId"
DisplayMemberPath
=
"Bezeichnung"
ItemsSource
=
"{Binding ElementName=me, Path=DataContext.ListAnrede}"
/>
</
StackPanel
>
<
StackPanel
Orientation
=
"Horizontal"
Grid.Row
=
"0"
Grid.Column
=
"1"
>
<
Label
Content
=
"Titel"
/>
<
telerik:DataFormComboBoxField
Height
=
"Auto"
DataMemberBinding
=
"{Binding Titel.Bezeichnung, Mode=TwoWay, NotifyOnValidationError=True, ValidatesOnExceptions=True}"
DisplayMemberPath
=
"Bezeichnung"
ItemsSource
=
"{Binding ElementName=me, Path=DataContext.ListTitel}"
/>
</
StackPanel
>
<
telerik:DataFormCheckBoxField
Grid.Row
=
"0"
Grid.Column
=
"2"
Label
=
"Deaktiviert"
DataMemberBinding
=
"{Binding Deaktiviert, Mode=TwoWay, NotifyOnValidationError=True, ValidatesOnExceptions=True}"
/>
<
telerik:DataFormDataField
Grid.Row
=
"1"
Grid.Column
=
"0"
Label
=
"Nachname"
DataMemberBinding
=
"{Binding Nachname, UpdateSourceTrigger=PropertyChanged, Mode=TwoWay, NotifyOnValidationError=True, ValidatesOnExceptions=True}"
/>
<
telerik:DataFormDataField
Grid.Row
=
"1"
Grid.Column
=
"1"
Label
=
"Vorname"
DataMemberBinding
=
"{Binding Vorname, UpdateSourceTrigger=PropertyChanged, Mode=TwoWay, NotifyOnValidationError=True, ValidatesOnExceptions=True}"
/>
<
telerik:DataFormDataField
Grid.Row
=
"2"
Grid.Column
=
"0"
Label
=
"Durchwahl"
DataMemberBinding
=
"{Binding Durchwahl, UpdateSourceTrigger=PropertyChanged, Mode=TwoWay, NotifyOnValidationError=True, ValidatesOnExceptions=True}"
/>
<
telerik:DataFormDataField
Grid.Row
=
"2"
Grid.Column
=
"1"
Label
=
"Mobilnummer"
DataMemberBinding
=
"{Binding Mobilnummer, UpdateSourceTrigger=PropertyChanged, Mode=TwoWay, NotifyOnValidationError=True, ValidatesOnExceptions=True, ValidatesOnDataErrors=True}"
/>
</
Grid
>
</
DataTemplate
>
</
UserControl.Resources
>
<
Grid
>
<
telerik:RadDataForm
CurrentItem
=
"{Binding Employee}"
Header
=
"{Binding Employee.Nachname}"
AutoEdit
=
"True"
CommandButtonsVisibility
=
"None"
EditTemplate
=
"{StaticResource EmployeeTemplate}"
AutoGenerateFields
=
"False"
/>
</
Grid
>
</
UserControl
>
namespace
Entities
{
using
System;
using
System.Collections.Generic;
using
System.ComponentModel.DataAnnotations;
public
partial
class
Mitarbeiter
{
public
Mitarbeiter()
{
this
.Veranstaltungsanmeldung =
new
HashSet<Veranstaltungsanmeldung>();
this
.Zustaendigkeit =
new
HashSet<Zustaendigkeit>();
}
public
int
MitarbeiterId {
get
;
set
; }
public
int
KundeId {
get
;
set
; }
public
int
AnredeId {
get
;
set
; }
public
int
TitelId {
get
;
set
; }
public
string
Vorname {
get
;
set
; }
public
string
Nachname {
get
;
set
; }
public
string
Durchwahl {
get
;
set
; }
public
string
Email {
get
;
set
; }
[Required(AllowEmptyStrings =
false
, ErrorMessage =
"Es muss eine Handynummer angegeben werden!"
)]
[Display(Name =
"Kunde"
)]
[RegularExpression(
"^\\+(\\d+)\\s\\((\\d+)\\)\\s(\\d+)(\\s-\\s(\\d+))?"
, ErrorMessage =
"Die Telefonnummer muss im Format +43 (XXX) XXXXX - XX sein"
)]
public
string
Mobilnummer {
get
;
set
; }
public
bool
Deaktiviert {
get
;
set
; }
public
string
Bild {
get
;
set
; }
public
System.DateTime UpdateDatum {
get
;
set
; }
public
string
UpdateBenutzer {
get
;
set
; }
public
virtual
Anrede Anrede {
get
;
set
; }
public
virtual
Kunde Kunde {
get
;
set
; }
public
virtual
Titel Titel {
get
;
set
; }
public
virtual
ICollection<Veranstaltungsanmeldung> Veranstaltungsanmeldung {
get
;
set
; }
public
virtual
ICollection<Zustaendigkeit> Zustaendigkeit {
get
;
set
; }
}
}