public class WPFBase : INotifyPropertyChanged { public event PropertyChangedEventHandler PropertyChanged; public void OnPropertyChanged( string PropertyName) { if (PropertyChanged != null ) { this .PropertyChanged( this , new PropertyChangedEventArgs(PropertyName)); } } public void OnPropertyChanged(MethodBase MethodeBase) { this .OnPropertyChanged(MethodeBase.Name.Substring(4)); } }
* This source code was highlighted with Source Code Highlighter .
public class WPFBase : INotifyPropertyChanged { public event PropertyChangedEventHandler PropertyChanged; public void OnPropertyChanged( string PropertyName) { if (PropertyChanged != null ) { this .PropertyChanged( this , new PropertyChangedEventArgs(PropertyName)); } } public void OnPropertyChanged(MethodBase MethodeBase) { this .OnPropertyChanged(MethodeBase.Name.Substring(4)); } }
* This source code was highlighted with Source Code Highlighter .public class WPFBase : INotifyPropertyChanged { public event PropertyChangedEventHandler PropertyChanged; public void OnPropertyChanged( string PropertyName) { if (PropertyChanged != null ) { this .PropertyChanged( this , new PropertyChangedEventArgs(PropertyName)); } } public void OnPropertyChanged(MethodBase MethodeBase) { this .OnPropertyChanged(MethodeBase.Name.Substring(4)); } }
* This source code was highlighted with Source Code Highlighter .public class WPFBase : INotifyPropertyChanged { public event PropertyChangedEventHandler PropertyChanged; public void OnPropertyChanged( string PropertyName) { if (PropertyChanged != null ) { this .PropertyChanged( this , new PropertyChangedEventArgs(PropertyName)); } } public void OnPropertyChanged(MethodBase MethodeBase) { this .OnPropertyChanged(MethodeBase.Name.Substring(4)); } }
* This source code was highlighted with Source Code Highlighter .public class WPFBase : INotifyPropertyChanged { public event PropertyChangedEventHandler PropertyChanged; public void OnPropertyChanged( string PropertyName) { if (PropertyChanged != null ) { this .PropertyChanged( this , new PropertyChangedEventArgs(PropertyName)); } } public void OnPropertyChanged(MethodBase MethodeBase) { this .OnPropertyChanged(MethodeBase.Name.Substring(4)); } }
* This source code was highlighted with Source Code Highlighter .public class WPFBase : INotifyPropertyChanged { public event PropertyChangedEventHandler PropertyChanged; public void OnPropertyChanged( string PropertyName) { if (PropertyChanged != null ) { this .PropertyChanged( this , new PropertyChangedEventArgs(PropertyName)); } } public void OnPropertyChanged(MethodBase MethodeBase) { this .OnPropertyChanged(MethodeBase.Name.Substring(4)); } }
* This source code was highlighted with Source Code Highlighter .public class WPFBase : INotifyPropertyChanged { public event PropertyChangedEventHandler PropertyChanged; public void OnPropertyChanged( string PropertyName) { if (PropertyChanged != null ) { this .PropertyChanged( this , new PropertyChangedEventArgs(PropertyName)); } } public void OnPropertyChanged(MethodBase MethodeBase) { this .OnPropertyChanged(MethodeBase.Name.Substring(4)); } }
* This source code was highlighted with Source Code Highlighter .public class WPFBase : INotifyPropertyChanged { public event PropertyChangedEventHandler PropertyChanged; public void OnPropertyChanged( string PropertyName) { if (PropertyChanged != null ) { this .PropertyChanged( this , new PropertyChangedEventArgs(PropertyName)); } } public void OnPropertyChanged(MethodBase MethodeBase) { this .OnPropertyChanged(MethodeBase.Name.Substring(4)); } }
* This source code was highlighted with Source Code Highlighter .public class WPFBase : INotifyPropertyChanged { public event PropertyChangedEventHandler PropertyChanged; public void OnPropertyChanged( string PropertyName) { if (PropertyChanged != null ) { this .PropertyChanged( this , new PropertyChangedEventArgs(PropertyName)); } } public void OnPropertyChanged(MethodBase MethodeBase) { this .OnPropertyChanged(MethodeBase.Name.Substring(4)); } }
* This source code was highlighted with Source Code Highlighter .public class WPFBase : INotifyPropertyChanged { public event PropertyChangedEventHandler PropertyChanged; public void OnPropertyChanged( string PropertyName) { if (PropertyChanged != null ) { this .PropertyChanged( this , new PropertyChangedEventArgs(PropertyName)); } } public void OnPropertyChanged(MethodBase MethodeBase) { this .OnPropertyChanged(MethodeBase.Name.Substring(4)); } }
* This source code was highlighted with Source Code Highlighter .public class WPFBase : INotifyPropertyChanged { public event PropertyChangedEventHandler PropertyChanged; public void OnPropertyChanged( string PropertyName) { if (PropertyChanged != null ) { this .PropertyChanged( this , new PropertyChangedEventArgs(PropertyName)); } } public void OnPropertyChanged(MethodBase MethodeBase) { this .OnPropertyChanged(MethodeBase.Name.Substring(4)); } }
* This source code was highlighted with Source Code Highlighter .public class WPFBase : INotifyPropertyChanged { public event PropertyChangedEventHandler PropertyChanged; public void OnPropertyChanged( string PropertyName) { if (PropertyChanged != null ) { this .PropertyChanged( this , new PropertyChangedEventArgs(PropertyName)); } } public void OnPropertyChanged(MethodBase MethodeBase) { this .OnPropertyChanged(MethodeBase.Name.Substring(4)); } }
* This source code was highlighted with Source Code Highlighter .public class WPFBase : INotifyPropertyChanged { public event PropertyChangedEventHandler PropertyChanged; public void OnPropertyChanged( string PropertyName) { if (PropertyChanged != null ) { this .PropertyChanged( this , new PropertyChangedEventArgs(PropertyName)); } } public void OnPropertyChanged(MethodBase MethodeBase) { this .OnPropertyChanged(MethodeBase.Name.Substring(4)); } }
* This source code was highlighted with Source Code Highlighter .public class WPFBase : INotifyPropertyChanged { public event PropertyChangedEventHandler PropertyChanged; public void OnPropertyChanged( string PropertyName) { if (PropertyChanged != null ) { this .PropertyChanged( this , new PropertyChangedEventArgs(PropertyName)); } } public void OnPropertyChanged(MethodBase MethodeBase) { this .OnPropertyChanged(MethodeBase.Name.Substring(4)); } }
* This source code was highlighted with Source Code Highlighter .public class WPFBase : INotifyPropertyChanged { public event PropertyChangedEventHandler PropertyChanged; public void OnPropertyChanged( string PropertyName) { if (PropertyChanged != null ) { this .PropertyChanged( this , new PropertyChangedEventArgs(PropertyName)); } } public void OnPropertyChanged(MethodBase MethodeBase) { this .OnPropertyChanged(MethodeBase.Name.Substring(4)); } }
* This source code was highlighted with Source Code Highlighter .public class WPFBase : INotifyPropertyChanged { public event PropertyChangedEventHandler PropertyChanged; public void OnPropertyChanged( string PropertyName) { if (PropertyChanged != null ) { this .PropertyChanged( this , new PropertyChangedEventArgs(PropertyName)); } } public void OnPropertyChanged(MethodBase MethodeBase) { this .OnPropertyChanged(MethodeBase.Name.Substring(4)); } }
* This source code was highlighted with Source Code Highlighter .public class WPFBase : INotifyPropertyChanged { public event PropertyChangedEventHandler PropertyChanged; public void OnPropertyChanged( string PropertyName) { if (PropertyChanged != null ) { this .PropertyChanged( this , new PropertyChangedEventArgs(PropertyName)); } } public void OnPropertyChanged(MethodBase MethodeBase) { this .OnPropertyChanged(MethodeBase.Name.Substring(4)); } }
* This source code was highlighted with Source Code Highlighter .
- public partial class Person: WPFBase
- {
- private string _Name;
- private string _Vorname;
- public string Vorname
- {
- get { return _Vorname; }
- set {_Vorname = value ; OnPropertyChanged (MethodInfo.GetCurrentMethod ()); }
- }
- public string Name
- {
- get { return _Name; }
- set {_Name = value ; OnPropertyChanged (MethodInfo.GetCurrentMethod ()); }
- }
- }
* This source code was highlighted with Source Code Highlighter .
- public partial class Person: IDataErrorInfo
- {
- public string Error
- {
- get
- {
- string error;
- StringBuilder sb = new StringBuilder ();
- error = this [ "Name" ];
- if (error! = string .Empty)
- sb.AppendLine (error);
- error = this [ "Vorname" ];
- if (error! = string .Empty)
- sb.AppendLine (error);
- if (! string .IsNullOrEmpty (sb.ToString ()))
- return sb.ToString ();
- return "" ;
- }
- }
- public string this [ string columnName]
- {
- get
- {
- switch (columnName)
- {
- case "Name" :
- if ( string .IsNullOrEmpty ( this .Name))
- Return "Enter the name !!!" ;
- break ;
- case "Vorname" :
- if ( string .IsNullOrEmpty ( this .Vorname))
- Return "Enter the surname !!!" ;
- break ;
- default :
- break ;
- }
- return "" ;
- }
- }
- }
* This source code was highlighted with Source Code Highlighter .
- public partial class Person: IEditableObject
- {
- bool inEdit = false ;
- Person tempPerson;
- public void BeginEdit ()
- {
- if (inEdit)
- return ;
- inEdit = true ;
- tempPerson = new Person ();
- tempPerson.Name = this .Name;
- tempPerson.Vorname = this .Vorname;
- }
- public void CancelEdit ()
- {
- if (! inEdit)
- return ;
- inEdit = false ;
- this .Name = tempPerson.Name;
- this .Vorname = tempPerson.Vorname;
- tempPerson = null ;
- }
- public void EndEdit ()
- {
- if (! inEdit)
- return ;
- inEdit = false ;
- tempPerson = null ;
- }
- }
* This source code was highlighted with Source Code Highlighter .
- public class ListPerson: ObservableCollection <Person>
- {
- public ListPerson ()
- {
- this .Add ( new Person ()
- {
- Name = "Ivanov" ,
- Vorname = "Sergey"
- });
- this .Add ( new Person ()
- {
- Name = "Petrov" ,
- Vorname = "Andrew"
- });
- }
- }
* This source code was highlighted with Source Code Highlighter .
- < Window.Resources >
- < dt: ListPerson x: Key = "ListPerson" />
- </ Windows.Resources >
* This source code was highlighted with Source Code Highlighter .
- < DataGrid ItemsSource = "{Binding Source = {StaticResource ListPerson}}" />
* This source code was highlighted with Source Code Highlighter .
- < DataGrid.RowValidationRules >
- < DataErrorValidationRule ValidationStep = "UpdatedValue" />
- </ DataGrid.RowValidationRules >
* This source code was highlighted with Source Code Highlighter .
- class ColumnValidation: ValidationRule
- {
- private ListPersonHelper _ListPerson;
- // This property is auxiliary; it is used to implement DependencyProperty
- public ListPersonHelper ListPerson
- {
- get { return _ListPerson; }
- set {_ListPerson = value ; }
- }
- // Check for valid data
- public override ValidationResult Validate
- ( object value , System.Globalization.CultureInfo cultureInfo)
- {
- BindingGroup bg = value as BindingGroup;
- Person person = bg.Items [0] as Person;
- // If there is an object with the same name or surname in the collection, we report an error!
- var result = from p in ListPerson.Items
- where p! = person &&
- (p.Name == person.Name
- || p.Vorname == person.Vorname)
- select p;
- if (result.Any ())
- {
- return new ValidationResult ( false , "First Name or Last Name already in the database" );
- }
- return ValidationResult.ValidResult;
- }
- }
- // Helper class for implementing DependencyProperty
- public class ListPersonHelper: DependencyObject
- {
- // You can privatize the data in the XAML property to the Items property, since it is declared as a DependencyProperty
- public ListPerson Items
- {
- get { return (ListPerson) GetValue (ItemsProperty); }
- set {SetValue (ItemsProperty, value ); }
- }
- public static readonly DependencyProperty ItemsProperty =
- DependencyProperty.Register
- ( "Items" ,
- typeof (ListPerson),
- typeof (ListPersonHelper),
- new UIPropertyMetadata ( null ));
- }
* This source code was highlighted with Source Code Highlighter .
- < Window x: Class = "DPTest.MainWindow"
- xmlns = "http://schemas.microsoft.com/winfx/2006/xaml/presentation"
- xmlns: x = "http://schemas.microsoft.com/winfx/2006/xaml"
- xmlns: dt = "clr-namespace: DPTest"
- Title = "MainWindow" Height = "437" Width = "684" >
- < Window.Resources >
- < dt: ListPerson x: Key = "ListPerson" />
- < dt: ListPersonHelper x: Key = "ListPersonHelper"
- Items = "{Binding Source = {StaticResource ListPerson}}" />
- < ControlTemplate x: Key = "GridError" >
- < Grid Margin = "0, -2.0, -2"
- ToolTip = "{Binding RelativeSource = {RelativeSource
FindAncestor, AncestorType = {x: Type DataGridRow}},
Path = (Validation.Errors) [0] .ErrorContent} "
>- < Ellipse StrokeThickness = "0" Fill = "Red"
- Width = "{TemplateBinding FontSize}"
- Height = "{TemplateBinding FontSize}" />
- < TextBlock Text = "!" FontSize = "{TemplateBinding FontSize}"
- FontWeight = "Bold" Foreground = "White"
- HorizontalAlignment = "Center" />
- </ Grid >
- </ ControlTemplate >
- </ Window.Resources >
- < Grid >
- < DataGrid ItemsSource = "{Binding Source = {StaticResource ListPerson}}"
- AutoGenerateColumns = "False"
- RowValidationErrorTemplate = "{StaticResource GridError}" >
- < DataGrid.Columns >
- < DataGridTextColumn
- Binding = "{Binding Path = Vorname}"
- Header = "Vorname" />
- < DataGridTextColumn
- Binding = "{Binding Path = Name}"
- Header = "Name" />
- </ DataGrid.Columns >
- < DataGrid.RowValidationRules >
- < DataErrorValidationRule
- ValidationStep = "UpdatedValue" />
- < dt: ColumnValidation
- ValidationStep = "UpdatedValue" >
- < dt: ColumnValidation.ListPerson >
- < dt: ListPersonHelper
- Items = "{Binding Source = {StaticResource ListPerson}}" />
- </ dt: ColumnValidation.ListPerson >
- </ dt: ColumnValidation >
- </ DataGrid.RowValidationRules >
- </ Datagrid >
- </ Grid >
- </ Window >
* This source code was highlighted with Source Code Highlighter .
Source: https://habr.com/ru/post/100532/
All Articles