バージョン

Name プロパティ (SpecialFilterOperandBase)

オペランドの名前。オペランドを一意に識別するために使用されます。
シンタックス
'宣言
 
Public MustOverride ReadOnly Property Name As String
public abstract string Name {get;}
使用例
Imports Infragistics.Windows
Imports Infragistics.Windows.Controls
Imports Infragistics.Windows.Editors
Imports Infragistics.Windows.DataPresenter
Imports Infragistics.Windows.DataPresenter.Events

    Public Sub New()
        ' Register the custom operands using SpecialFilterOperands.Register method
        ' to integrate them with the filtering UI. The data presenter will automatically
        ' display these operands as options in the filter drop-down of fields with
        ' matching data type.
        ' 
        ' Register Odd and then Even operands.
        SpecialFilterOperands.Register(EvenOrOddOperand.Even)
        SpecialFilterOperands.Register(EvenOrOddOperand.Odd)

        InitializeComponent()
    End Sub

    ''' <summary>
    ''' Filter operand used to filter odd or even values.
    ''' </summary>
    Public Class EvenOrOddOperand
        Inherits SpecialFilterOperandBase


        ' These static instances can be used in XAML to specify initial filters.
        ' 
        Public Shared ReadOnly Even As EvenOrOddOperand = New EvenOrOddOperand(False)
        Public Shared ReadOnly Odd As EvenOrOddOperand = New EvenOrOddOperand(True)

        Private _isOdd As Boolean

        ''' <summary>
        ''' Constructor
        ''' </summary>
        ''' <param name="isOdd">Whether this instance will filter odd values or even values.</param>
        Private Sub New(ByVal isOdd As Boolean)
            _isOdd = isOdd
        End Sub

        ' Name of the operand. This is never displayed to the end user. It's a way to
        ' identify the operand in code.
        Public Overrides ReadOnly Property Name() As String
            Get
                Return IIf(_isOdd, "Odd", "Even")
            End Get
        End Property

        ' Description of the operand.
        Public Overrides ReadOnly Property Description() As Object
            Get
                Return IIf(_isOdd, "Odd values", "Even values")
            End Get
        End Property

        ' The text that gets displayed to represent this operand.
        Public Overrides ReadOnly Property DisplayContent() As Object
            Get
                Return IIf(_isOdd, "Odd", "Even")
            End Get
        End Property



        Public Overrides Function IsMatch(ByVal comparisonOperator As Infragistics.Windows.Controls.ComparisonOperator, ByVal value As Object, ByVal context As Infragistics.Windows.Controls.ConditionEvaluationContext) As Boolean
            ' This method will only get called for operators that we indicated as supported in
            ' the SupportsOperator method.
            If comparisonOperator.Equals = comparisonOperator Then
                Dim valueAsDouble As Double = context.CurrentValue.ValueAsDouble
                If Not Double.IsNaN(valueAsDouble) Then
                    If _isOdd Then
                        Return 1 = (CType(valueAsDouble, Integer) Mod 2)

                    Else
                        Return 0 = (CType(valueAsDouble, Integer) Mod 2)
                    End If
                End If

                ' If the value is not a valid number (it's null for example), then return false
                ' since it's neither odd nor even.
                Return False
            ElseIf comparisonOperator.NotEquals = comparisonOperator Then
                ' For NotEquals, simply negate the result of Equals.
                Return Not Me.IsMatch(comparisonOperator.Equals, value, context)
            Else
                Return False
            End If
        End Function

        Public Overrides Function SupportsDataType(ByVal type As System.Type) As Boolean
            ' This operand supports int and nullable int types. Data presenter will automatically
            ' show this operand in filter drop-down of fields with int and int? data types. All
            ' you have to do is register the operand using SpecialFilterOperands.Register as we
            ' are doing in the InitializeComponent.
            ' 
            Return type Is GetType(Integer) OrElse type Is GetType(Nullable(Of Integer))
        End Function
			

        Public Overrides Function SupportsOperator(ByVal comparisonOperator As Infragistics.Windows.Controls.ComparisonOperator) As Boolean
            ' Only Equals and NotEquals operators make sense for this operand. NotEquals
            ' is probably not that useful for this operand however for demonstration purposes
            ' we'll include it here.
            ' 
            Return comparisonOperator.Equals = comparisonOperator _
              OrElse comparisonOperator.NotEquals = comparisonOperator
        End Function


        Public Overrides ReadOnly Property UsesAllValues() As Boolean
            Get
                ' NOTE: This property is only applicable if you want to create advanced operands that
                ' rely on data from all records to test a value for match, for example AboveAverage.
                ' 
                ' UsesAllValues is used to indicate that the operand relies on all the values 
                ' of the records to work. Examples of such operands would be AboveAverage, BelowAverage,
                ' Top10 etc... With AboveAverage for example, to check if a value is above average,
                ' we need to calculate the average of all the values. Such an operand would return true
                ' from this property. It would then use the context.AllValues (context is passed into
                ' the IsMatch) to calculate the average of all values and check if a particular value
                ' is above the calculated average. Note that There is a way to cache the calculated 
                ' value via the context.UserCache property - that way the average doesn't have to be 
                ' re-calculated for every value that IsMatch will be called for. The data presenter will 
                ' manage the cache and clear it when cell data changes so all you have to do is check 
                ' if context.UserCache is null and if so recalculate it and cache it again on the 
                ' context.UserCache.
                ' 

                Return False
            End Get
        End Property

    End Class
using Infragistics.Windows;
using Infragistics.Windows.Controls;
using Infragistics.Windows.Editors;
using Infragistics.Windows.DataPresenter;
using Infragistics.Windows.DataPresenter.Events;

		public Window1( )
		{
			// Register the custom operands using SpecialFilterOperands.Register method
			// to integrate them with the filtering UI. The data presenter will automatically
			// display these operands as options in the filter drop-down of fields with
			// matching data type.
			// 
			// Register Odd and then Even operands.
			SpecialFilterOperands.Register( EvenOrOddOperand.Even );
			SpecialFilterOperands.Register( EvenOrOddOperand.Odd );

			InitializeComponent( );
		}



		/// <summary>
		/// Filter operand used to filter odd or even values.
		/// </summary>
		public class EvenOrOddOperand : SpecialFilterOperandBase
		{
			// These static instances can be used in XAML to specify initial filters.
			// 
			public static readonly EvenOrOddOperand Even = new EvenOrOddOperand( false );
			public static readonly EvenOrOddOperand Odd = new EvenOrOddOperand( true );

			private bool _isOdd;

			/// <summary>
			/// Constructor
			/// </summary>
			/// <param name="isOdd">Whether this instance will filter odd values or even values.</param>
			private EvenOrOddOperand( bool isOdd )
			{
				_isOdd = isOdd;
			}

			// Name of the operand. This is never displayed to the end user. It's a way to
			// identify the operand in code.
			public override string Name
			{
				get
				{
					return _isOdd ? "Odd" : "Even";
				}
			}

			// Description of the operand.
			public override object Description
			{
				get
				{
					return _isOdd ? "Odd values" : "Even values";
				}
			}

			// The text that gets displayed to represent this operand.
			public override object DisplayContent
			{
				get
				{
					return _isOdd ? "Odd" : "Even";
				}
			}


			public override bool IsMatch( ComparisonOperator comparisonOperator, object value, ConditionEvaluationContext context )
			{
				// This method will only get called for operators that we indicated as supported in
				// the SupportsOperator method.
				// 
				if ( ComparisonOperator.Equals == comparisonOperator )
				{
					double valueAsDouble = context.CurrentValue.ValueAsDouble;
					if ( !double.IsNaN( valueAsDouble ) )
					{
						if ( _isOdd )
							return 1 == (int)valueAsDouble % 2;
						else
							return 0 == (int)valueAsDouble % 2;
					}

					// If the value is not a valid number (it's null for example), then return false
					// since it's neither odd nor even.
					// 
					return false;
				}
				else if ( ComparisonOperator.NotEquals == comparisonOperator )
				{
					// For NotEquals, simply negate the result of Equals.
					// 
					return !this.IsMatch( ComparisonOperator.Equals, value, context );
				}
				else
				{
					return false;
				}
			}

			public override bool SupportsDataType( Type type )
			{
				// This operand supports int and nullable int types. Data presenter will automatically
				// show this operand in filter drop-down of fields with int and int? data types. All
				// you have to do is register the operand using SpecialFilterOperands.Register as we
				// are doing in the InitializeComponent.
				// 
				return typeof( int ) == type
					|| typeof( int? ) == type;
			}

			public override bool SupportsOperator( ComparisonOperator comparisonOperator )
			{
				// Only Equals and NotEquals operators make sense for this operand. NotEquals
				// is probably not that useful for this operand however for demonstration purposes
				// we'll include it here.
				// 
				return ComparisonOperator.Equals == comparisonOperator
					|| ComparisonOperator.NotEquals == comparisonOperator;
			}

			public override bool UsesAllValues
			{
				get
				{
					// NOTE: This property is only applicable if you want to create advanced operands that
					// rely on data from all records to test a value for match, for example AboveAverage.
					// 
					// UsesAllValues is used to indicate that the operand relies on all the values 
					// of the records to work. Examples of such operands would be AboveAverage, BelowAverage,
					// Top10 etc... With AboveAverage for example, to check if a value is above average,
					// we need to calculate the average of all the values. Such an operand would return true
					// from this property. It would then use the context.AllValues (context is passed into
					// the IsMatch) to calculate the average of all values and check if a particular value
					// is above the calculated average. Note that There is a way to cache the calculated 
					// value via the context.UserCache property - that way the average doesn't have to be 
					// re-calculated for every value that IsMatch will be called for. The data presenter will 
					// manage the cache and clear it when cell data changes so all you have to do is check 
					// if context.UserCache is null and if so recalculate it and cache it again on the 
					// context.UserCache.
					// 

					return false;
				}
			}
		}
参照