Xceed Toolkit Plus for WPF v5.1 Documentation
Xceed.Wpf.DataGrid.Toolkit Assembly / Xceed.Wpf.DataGrid Namespace / DataGridBindingInfo Class
Members Example


In This Topic
    DataGridBindingInfo Class
    In This Topic
    Class that creates and wraps a binding that is used by a column to retrieve and validate its values.
    Syntax
    'Declaration
     
    Public Class DataGridBindingInfo 
    'Usage
     
    Dim instance As DataGridBindingInfo
    public class DataGridBindingInfo 
    Remarks

    The following table provides a list of the underlying binding's properties and their immutable values.

    Property Value
    Mode Property BindingMode.TwoWay (see ReadOnly property)
    UpdateSourceTrigger Property UpdateSourceTriggerExplicit (see UpdateSourceTrigger property)
    ValidatesOnDataErrors Property true
    ValidatesOnExceptions Property true
    NotifyOnTargetUpdated Property true
    NotifyOnValidationError Property true
    Example

    All examples in this topic assume that the grid is bound to a list of Composer objects, unless stated otherwise.

    The following example demonstrates how to create a custom ValidationRule and apply it to a column's binding to provide binding-level validation.
    <Grid xmlns:xcdg="http://schemas.xceed.com/wpf/xaml/datagrid"
         xmlns:local="clr-namespace:Xceed.Wpf.Documentation">
      <Grid.Resources>
         <xcdg:DataGridCollectionViewSource x:Key="cvs_composers"
                                            Source="{Binding Source={x:Static Application.Current}, 
                                                             Path=Composers}"/>
      </Grid.Resources>
     
      <xcdg:DataGridControl ItemsSource="{Binding Source={StaticResource cvs_composers}}"
                            UpdateSourceTrigger="RowEndingEdit">
         <xcdg:DataGridControl.Columns> 
           <xcdg:Column FieldName="BirthYear">
              <xcdg:Column.DisplayMemberBindingInfo>
                 <xcdg:DataGridBindingInfo Path="BirthYear">
                    <xcdg:DataGridBindingInfo.ValidationRules>
                       <local:YearValidationRule />
                    </xcdg:DataGridBindingInfo.ValidationRules>
                 </xcdg:DataGridBindingInfo>
              </xcdg:Column.DisplayMemberBindingInfo>
           </xcdg:Column>
    
           <xcdg:Column FieldName="DeathYear">
              <xcdg:Column.DisplayMemberBindingInfo>
                 <xcdg:DataGridBindingInfo Path="DeathYear">
                    <xcdg:DataGridBindingInfo.ValidationRules>
                       <local:YearValidationRule />
                    </xcdg:DataGridBindingInfo.ValidationRules>
                 </xcdg:DataGridBindingInfo>
              </xcdg:Column.DisplayMemberBindingInfo>
           </xcdg:Column>      
        </xcdg:DataGridControl.Columns>
      </xcdg:DataGridControl>
    </Grid>
    Implementation of the YearValidationRule validation rule.
    Imports System
    Imports System.Windows.Controls
    Imports System.Globalization
    Namespace Xceed.Wpf.Documentation
    
      Public Class YearValidationRule
                   Inherits ValidationRule
    
        Public Overrides Function Validate( ByVal value As Object, _
                                            ByVal cultureInfo As CultureInfo ) As ValidationResult
          Dim year As Integer = CInt( value )
          If year > DateTime.Now.Year Then
            Return New ValidationResult( False, "Chosen year cannot be greater than this year." )
          End If
          Return ValidationResult.ValidResult
        End Function
      End Class
    End Namespace
    Implementation of the YearValidationRule validation rule.
    using System;
    using System.Windows.Controls;
    using System.Globalization;
    namespace Xceed.Wpf.Documentation
    {
    
     public class YearValidationRule : ValidationRule
     {
       public override ValidationResult Validate( object value, CultureInfo cultureInfo )
       {
         int year = ( int )value;
         if( year > DateTime.Now.Year )
           return new ValidationResult( false, "Chosen year cannot be greater than this year." );
         return ValidationResult.ValidResult;
       }
     }
    }
    Inheritance Hierarchy

    System.Object
       Xceed.Wpf.DataGrid.DataGridBindingInfo

    Public Constructors
     NameDescription
    Public ConstructorInitializes a new instance of the DataGridBindingInfo class.  
    Top
    Public Properties
     NameDescription
    Public PropertyGets or sets a value indicating whether the Path is evaluated relative to the data item or the data source.  
    Public PropertyGets or sets the convert that will be used to convert the value returned by the binding.  
    Public PropertyGets or sets the CultureInfo in which the values returned by the Converter will be evaluated.  
    Public PropertyGets or sets the parameter that will be passed to the Converter.  
    Public PropertyGets or sets the name of the element that will be used as the binding source object.  
    Public PropertyGets or sets the value that will be used when the binding is unable to return a value.  
    Public Property  
    Public PropertyGets or sets a value indicating whether to provide notification when a value is transferred from the binding target to the binding source.  
    Public PropertyGets or sets the path to the binding source property.  
    Public PropertyGets or sets a value indicate whether the binding is read-only.  
    Public PropertyGets or sets a callback that can be handled to provide custom logic for when an exception is thrown by the binding engine during the update of the binding source value.  
    Public PropertyGets a collection of rules that will be used to validate user input.  
    Public PropertyGets or sets the XPath query that returns the value to use on the XML binding source.  
    Top
    Requirements

    Target Platforms: Windows 11, Windows 10, Windows 7, Windows Vista SP1 or later, Windows XP SP3, Windows Server 2008 (Server Core not supported), Windows Server 2008 R2 (Server Core supported with SP1 or later), Windows Server 2003 SP2

    See Also