Windows apps
Collapse the table of content
Expand the table of content
Information
The topic you requested is included in another documentation set. For convenience, it's displayed below. Choose Switch to see the topic in its original location.

BindingGroup.GetValue Method (Object, String)

 

Returns the proposed value for the specified property and item.

Namespace:   System.Windows.Data
Assembly:  PresentationFramework (in PresentationFramework.dll)

Public Function GetValue (
	item As Object,
	propertyName As String
) As Object

Parameters

item
Type: System.Object

The object that contains the specified property.

propertyName
Type: System.String

The property whose proposed value to get.

Return Value

Type: System.Object

The proposed property value.

Exception Condition
InvalidOperationException

There is not a binding for the specified item and property.

ValueUnavailableException

The value of the specified property is not available, due to a conversion error or because an earlier validation rule failed.

Use this method in the ValidationRule.Validate method to get the value to be committed to the source. The type of the return value depends on the stage at which the ValidationRule occurs. For example, if a TextBox is data bound to a property of type integer and the ValidationRule that calls GetValue(Object, String) has its ValidationStep set to RawProposedValue, the method returns a string. If the ValidationRule has its ValidationStep set to ConvertedProposedValue, the method returns whatever type that is returned by the binding's converter. In this example, GetValue(Object, String) usually returns an integer.

The following example is part of an application that prompts the user to enter multiple customers and assign a sales representative to each customer. The application checks that the sales representative and the customer belong to the same region. The example shows the Validate method, which uses the GetValue(Object, String) method to get values that the customer entered.

Public Class AreasMatch
	Inherits ValidationRule
	Public Overrides Function Validate(ByVal value As Object, ByVal cultureInfo As System.Globalization.CultureInfo) As ValidationResult
		Dim bg As BindingGroup = TryCast(value, BindingGroup)
		Dim cust As Customer = TryCast(bg.Items(0), Customer)

		If cust Is Nothing Then
			Return New ValidationResult(False, "Customer is not the source object")
		End If

		Dim region As Region = CType(bg.GetValue(cust, "Location"), Region)
		Dim rep As ServiceRep = TryCast(bg.GetValue(cust, "ServiceRepresentative"), ServiceRep)
		Dim customerName As String = TryCast(bg.GetValue(cust, "Name"), String)

		If region = rep.Area Then
			Return ValidationResult.ValidResult
		Else

			Dim sb As New StringBuilder()
			sb.AppendFormat("{0} must be assigned a sales representative that serves the {1} region. " & vbLf & " ", customerName, region)
			Return New ValidationResult(False, sb.ToString())
		End If
	End Function
End Class

.NET Framework
Available since 3.0
Return to top
Show:
© 2017 Microsoft