2011-01-10 3 views
0

HI、 はシルバーWCFサービスを使用していますし、私のDataContractのクラスは参照ファイルで公開されており、DataGridのためにクラス型のコレクションを結合し、特定の行をクリックしながらしていますデータ全体を編集するためのデータがデータフォームにバインドされ、そこでフィールドを検証する必要があります。ここではIDataErrorInfo validateへのインターフェイスです。ここでは、サービス参照ファイルでクラスが部分クラスであり、サービスファイルとクラス名の同じ名前空間が実装されましたIDataErrorInfoインターフェイスプロパティDatavalidation

この[ストリング COLUMNNAME] {}

それは誰もがこれを助けることができる動作していない.But iが検証worte範囲で

パブリックストリング。 ありがとう

答えて

1

Silverlight 4とWCFを使用すると、RequiredAttributeやDisplayAttributeなどのデータ注釈が生成されたクライアントサイドファイルに伝播されません。 この問題の一つの解決策... がモデルとクラスライブラリを作成している(Model.dll)サービスのプロジェクト参照で サンプル


public partial class Person: INotifyPropertyChanged 
{ 
    private Guid IDField; 

    private string NameField; 

    private string LastNameField; 

    private int AgeField; 

    private string EmailField; 

    /// <summary> 
    /// ID of an Object 
    /// </summary>   
    public Guid ID 
    { 
     get 
     { 
      return IDField; 
     } 
     set 
     { 
      if (value != IDField) 
      { 
       Validator.ValidateProperty(value, new ValidationContext(this, null, null) { MemberName = "ID" }); 
       IDField = value; 
       OnPropertyChanged("ID"); 
      } 
     } 
    } 

    /// <summary> 
    /// Name of a person 
    /// </summary> 
    [Required]   
    public string Name 
    { 
     get 
     { 
      return NameField; 
     } 
     set 
     { 
      if (value != NameField) 
      { 
       Validator.ValidateProperty(value, new ValidationContext(this, null, null) { MemberName = "Name" }); 
       NameField = value; 
       OnPropertyChanged("Name"); 
      } 
     } 
    } 

    /// <summary> 
    /// LastName of a person 
    /// </summary> 
    [Required] 
    public string LastName 
    { 
     get 
     { 
      return LastNameField; 
     } 
     set 
     { 
      if (value != LastNameField) 
      { 
       Validator.ValidateProperty(value, new ValidationContext(this, null, null) { MemberName = "LastName" }); 
       LastNameField = value; 
       OnPropertyChanged("LastName"); 
      } 
     } 
    } 

    /// <summary> 
    /// Age of a person 
    /// </summary> 
    [Range(0,120)] 
    //[Required] 
    public int Age 
    { 
     get 
     { 
      return AgeField; 
     } 
     set 
     { 
      if (value != AgeField) 
      { 
       Validator.ValidateProperty(value, new ValidationContext(this, null, null) { MemberName = "Age" }); 
       AgeField = value; 
       OnPropertyChanged("Age"); 
      } 
     } 
    } 

    [RegularBLOCKED EXPRESSION] 
    public string Email 
    { 
     get 
     { 
      return EmailField; 
     } 
     set 
     { 
      if (value != EmailField) 
      { 
       Validator.ValidateProperty(value, new ValidationContext(this, null, null) { MemberName = "Email" }); 
       EmailField = value; 
       OnPropertyChanged("Email"); 
      } 
     } 
    } 

    public event PropertyChangedEventHandler PropertyChanged; 

    /// <summary> 
    /// Raises a property changed notification for the specified property name. 
    /// </summary> 
    /// <param name="propName">The name of the property that changed.</param> 
    protected virtual void OnPropertyChanged(string propName) 
    { 
     if (PropertyChanged != null) 
     { 
      PropertyChanged(this, new PropertyChangedEventArgs(propName)); 
     } 
    } 
} 

このクラスライブラリ サンプルサービスの可能性があります...

[ServiceContract] 
    public interface IPersonService 
    { 
     [OperationContract] 
     List<Person> GetPersons(); 

     [OperationContract] 
     Person GetPersonByID(Guid ID); 

     [OperationContract] 
     void EditPerson(Person PersonField);   

    } 


///////////////// 



public class PersonService : IPersonService 
    { 
     private List<Person> Persons; 

     public PersonService() 
     { 
      Persons = new List<Person>(); 
      Persons.Add(new Person { ID = Guid.NewGuid(), Name = "Albert", LastName = "Pujols" , Age = 31, Email = "[email protected]" }); 
      Persons.Add(new Person { ID = Guid.NewGuid(), Name = "Alex", LastName = "Rodriguez", Age = 36, Email = "[email protected]" }); 
      Persons.Add(new Person { ID = Guid.NewGuid(), Name = "Evan", LastName = "Longoria", Age = 25, Email = "[email protected]" }); 
      Persons.Add(new Person { ID = Guid.NewGuid(), Name = "Joey", LastName = "Votto", Age = 25, Email = "[email protected]" }); 
      Persons.Add(new Person { ID = Guid.NewGuid(), Name = "Miguel", LastName = "Cabrera", Age = 27, Email = "[email protected]" }); 
      Persons.Add(new Person { ID = Guid.NewGuid(), Name = "Kendry", LastName = "Morales", Age = 26, Email = "[email protected]" }); 
      Persons.Add(new Person { ID = Guid.NewGuid(), Name = "Alexei", LastName = "Ramirez", Age = 28, Email = "[email protected]" }); 
     } 


     public List<Person> GetPersons() 
     { 
      return Persons; 
     } 

     public Person GetPersonByID(Guid ID) 
     { 
      return (from sel in Persons where sel.ID == ID select sel).First(); 
     } 

     public void EditPerson(Person PersonField) 
     { 
      Person Person = (from sel in Persons where sel.ID == PersonField.ID select sel).First(); 
      Person = PersonField; 
     }   

    } 

シルバーライトクラスライブラリ(SL.Model.dll)を作成します(このライブラリにはサンプルm odelはModel.dllで作成されました)
このクラスライブラリの既存のItemをリンクとして追加し、Model.dllを持つモデルアイテムを追加します。 SilverlightアプリケーションリファレンスSL.Model.dll サービス参照は再利用タイプの作成ビューです(それはdeafaultオプションです)ページの サンプル... XAMLコントロールの

<UserControl x:Class="SampleApp.MainPage" 
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" 
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" 
    xmlns:d="http://schemas.microsoft.com/expression/blend/2008" 
    xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 
    mc:Ignorable="d" 
      xmlns:dataInput="clr-namespace:System.Windows.Controls;assembly=System.Windows.Controls.Data.Input" 
    d:DesignHeight="300" d:DesignWidth="400" xmlns:sdk="http://schemas.microsoft.com/winfx/2006/xaml/presentation/sdk"> 

    <Grid x:Name="LayoutRoot" Background="White"> 
     <Grid.ColumnDefinitions> 
      <ColumnDefinition Width="55*" /> 
      <ColumnDefinition Width="45*" /> 
     </Grid.ColumnDefinitions> 
     <sdk:DataGrid Name="dataGrid1" Grid.Column="0" IsReadOnly="True" AutoGenerateColumns="False" SelectionChanged="dataGrid1_SelectionChanged" FontSize="12"> 
      <sdk:DataGrid.Columns> 
       <sdk:DataGridTextColumn CanUserSort="True" Binding="{Binding ID}" Visibility="Collapsed" /> 
       <sdk:DataGridTextColumn CanUserSort="True" Binding="{Binding Name}" Header="Name" Width="100" /> 
       <sdk:DataGridTextColumn CanUserSort="True" Binding="{Binding LastName}" Header="LastName" Width="100" />     
      </sdk:DataGrid.Columns> 
     </sdk:DataGrid> 
     <Grid Grid.Column="1"> 
      <Grid.ColumnDefinitions> 
       <ColumnDefinition Width="40*" /> 
       <ColumnDefinition Width="50*" /> 
       <ColumnDefinition Width="10*" /> 
      </Grid.ColumnDefinitions> 
      <Grid.RowDefinitions> 
       <RowDefinition Height="30"/> 
       <RowDefinition Height="30"/> 
       <RowDefinition Height="30"/> 
       <RowDefinition Height="30"/> 
       <RowDefinition Height="150"/> 
      </Grid.RowDefinitions> 
      <TextBlock HorizontalAlignment="Right" VerticalAlignment="Center" Text="Name" Grid.Row="0" Margin="4" /> 
      <TextBox x:Name="Name" Text="{Binding Name, Mode=TwoWay, ValidatesOnExceptions=true, NotifyOnValidationError=true}" Grid.Row="0" Grid.Column="1" Margin="4" /> 

      <TextBlock HorizontalAlignment="Right" VerticalAlignment="Center" Text="LastName" Grid.Row="1" Margin="4" /> 
      <TextBox x:Name="LName" Text="{Binding LastName, Mode=TwoWay, ValidatesOnExceptions=true, NotifyOnValidationError=true}" Grid.Row="1" Grid.Column="1" Margin="4" /> 

      <TextBlock HorizontalAlignment="Right" VerticalAlignment="Center" Text="Age" Grid.Row="2" Margin="4" /> 
      <TextBox x:Name="Age" Text="{Binding Age, Mode=TwoWay, ValidatesOnExceptions=true, NotifyOnValidationError=true}" Grid.Row="2" Grid.Column="1" Margin="4" /> 

      <TextBlock HorizontalAlignment="Right" VerticalAlignment="Center" Text="Email" Grid.Row="3" Margin="4" /> 
      <TextBox x:Name="Email" Text="{Binding Email, Mode=TwoWay, ValidatesOnExceptions=true, NotifyOnValidationError=true}" Grid.Row="3" Grid.Column="1" Margin="4" /> 

      <dataInput:ValidationSummary Margin="4" Grid.Row="4" Grid.ColumnSpan="3" /> 


     </Grid> 



    </Grid> 
</UserControl> 

コード... chekedさ

public partial class MainPage : UserControl 
    { 
     private PersonServiceClient Client; 
     private EndpointAddress AddressService = new EndpointAddress(new Uri("http://localhost:3589/PersonService.svc")); 

     public MainPage() 
     { 
      InitializeComponent(); 

      Client = new PersonServiceClient(new BasicHttpBinding(), AddressService); 
      Client.GetPersonsAsync(); 
      Client.GetPersonsCompleted += new EventHandler<GetPersonsCompletedEventArgs>(Client_GetPersonsCompleted); 
     } 

     void Client_GetPersonsCompleted(object sender, GetPersonsCompletedEventArgs e) 
     { 
      ObservableCollection<Person> PersonItems = e.Result; 
      dataGrid1.ItemsSource = PersonItems;    
     } 

     private void dataGrid1_SelectionChanged(object sender, SelectionChangedEventArgs e) 
     { 
      DataContext = e.AddedItems[0]; 
     } 
    } 
関連する問題