本文整理匯總了VB.NET中System.Windows.Data.BindingGroup類的典型用法代碼示例。如果您正苦於以下問題:VB.NET BindingGroup類的具體用法?VB.NET BindingGroup怎麽用?VB.NET BindingGroup使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。
在下文中一共展示了BindingGroup類的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的VB.NET代碼示例。
示例1: ItemError
Private Sub Submit_Click(ByVal sender As Object, ByVal e As RoutedEventArgs)
If stackPanel1.BindingGroup.CommitEdit() Then
MessageBox.Show("Item submitted")
stackPanel1.BindingGroup.BeginEdit()
End If
End Sub
' This event occurs when a ValidationRule in the BindingGroup
' or in a Binding fails.
Private Sub ItemError(ByVal sender As Object, ByVal e As ValidationErrorEventArgs)
If e.Action = ValidationErrorEventAction.Added Then
MessageBox.Show(e.Error.ErrorContent.ToString())
End If
End Sub
Private Sub stackPanel1_Loaded(ByVal sender As Object, ByVal e As RoutedEventArgs)
' Set the DataContext to a PurchaseItem object.
' The BindingGroup and Binding objects use this as
' the source.
stackPanel1.DataContext = New PurchaseItem()
' Begin an edit transaction that enables
' the object to accept or roll back changes.
stackPanel1.BindingGroup.BeginEdit()
End Sub
Private Sub Cancel_Click(ByVal sender As Object, ByVal e As RoutedEventArgs)
' Cancel the pending changes and begin a new edit transaction.
stackPanel1.BindingGroup.CancelEdit()
stackPanel1.BindingGroup.BeginEdit()
End Sub
示例2: ValidateDateAndPrice
Public Class ValidateDateAndPrice
Inherits ValidationRule
' Ensure that an item over $100 is available for at least 7 days.
Public Overrides Function Validate(ByVal value As Object, ByVal cultureInfo As CultureInfo) As ValidationResult
Dim bg As BindingGroup = TryCast(value, BindingGroup)
' Get the source object.
Dim item As PurchaseItem = TryCast(bg.Items(0), PurchaseItem)
Dim doubleValue As Object = Nothing
Dim dateTimeValue As Object = Nothing
' Get the proposed values for Price and OfferExpires.
Dim priceResult As Boolean = bg.TryGetValue(item, "Price", doubleValue)
Dim dateResult As Boolean = bg.TryGetValue(item, "OfferExpires", dateTimeValue)
If (Not priceResult) OrElse (Not dateResult) Then
Return New ValidationResult(False, "Properties not found")
End If
Dim price As Double = CDbl(doubleValue)
Dim offerExpires As Date = CDate(dateTimeValue)
' Check that an item over $100 is available for at least 7 days.
If price > 100 Then
If offerExpires < Date.Today + New TimeSpan(7, 0, 0, 0) Then
Return New ValidationResult(False, "Items over $100 must be available for at least 7 days.")
End If
End If
Return ValidationResult.ValidResult
End Function
End Class