ItemsControl.ItemBindingGroup Vlastnost
Definice
Důležité
Některé informace platí pro předběžně vydaný produkt, který se může zásadně změnit, než ho výrobce nebo autor vydá. Microsoft neposkytuje žádné záruky, výslovné ani předpokládané, týkající se zde uváděných informací.
Získá nebo nastaví BindingGroup , který je zkopírován do každé položky v objektu ItemsControl.
public:
property System::Windows::Data::BindingGroup ^ ItemBindingGroup { System::Windows::Data::BindingGroup ^ get(); void set(System::Windows::Data::BindingGroup ^ value); };
[System.ComponentModel.Bindable(true)]
public System.Windows.Data.BindingGroup ItemBindingGroup { get; set; }
[<System.ComponentModel.Bindable(true)>]
member this.ItemBindingGroup : System.Windows.Data.BindingGroup with get, set
Public Property ItemBindingGroup As BindingGroup
Hodnota vlastnosti
Tato BindingGroup položka se zkopíruje do každé položky v objektu ItemsControl.
- Atributy
Příklady
Následující příklad je součástí aplikace, která uživatele vyzve, aby zadal více zákazníků a každému zákazníkovi přiřadil prodejního zástupce a pak zkontroluje, jestli prodejní zástupce a zákazník patří do stejné oblasti. Příklad nastaví tak ItemBindingGroupItemsControlValidationRule, aby , , AreasMatchbude ověřovat každou položku. Příklad také vytvoří Label chybu ověření. Všimněte si, že Content je vázán Label na ValidationError to, že získá z Validation.ValidationAdornerSiteForProperty vlastnosti. Hodnota Validation.ValidationAdornerSiteForProperty je kontejner položek, u kterého došlo k chybě.
<ItemsControl Name="customerList" ItemTemplate="{StaticResource ItemTemplate}"
ItemsSource="{Binding}">
<ItemsControl.ItemBindingGroup>
<BindingGroup>
<BindingGroup.ValidationRules>
<src:AreasMatch/>
</BindingGroup.ValidationRules>
</BindingGroup>
</ItemsControl.ItemBindingGroup>
<ItemsControl.ItemContainerStyle>
<Style TargetType="{x:Type ContentPresenter}">
<Setter Property="Validation.ValidationAdornerSite"
Value="{Binding ElementName=validationErrorReport}"/>
</Style>
</ItemsControl.ItemContainerStyle>
</ItemsControl>
<Label Name="validationErrorReport"
Content="{Binding RelativeSource={RelativeSource Self},
Path=(Validation.ValidationAdornerSiteFor).(Validation.Errors)[0].ErrorContent}"
Margin="5" Foreground="Red" HorizontalAlignment="Center"/>
Následující příklad získá kontejner položek a zavolá UpdateSources kontejner kontejneru BindingGroup k ověření dat. Data je nutné ověřit voláním metody v kontejneru BindingGrouppoložek , nikoli v objektu ItemBindingGroupItemsControl.
void saveCustomer_Click(object sender, RoutedEventArgs e)
{
Button btn = sender as Button;
FrameworkElement container = (FrameworkElement) customerList.ContainerFromElement(btn);
// If the user is trying to change an items, when another item has an error,
// display a message and cancel the currently edited item.
if (bindingGroupInError != null && bindingGroupInError != container.BindingGroup)
{
MessageBox.Show("Please correct the data in error before changing another customer");
container.BindingGroup.CancelEdit();
return;
}
if (container.BindingGroup.UpdateSources())
{
bindingGroupInError = null;
MessageBox.Show("Item Saved");
}
else
{
bindingGroupInError = container.BindingGroup;
}
}
Private Sub saveCustomer_Click(ByVal sender As Object, ByVal e As RoutedEventArgs)
Dim btn As Button = TryCast(sender, Button)
Dim container As FrameworkElement = CType(customerList.ContainerFromElement(btn), FrameworkElement)
' If the user is trying to change an items, when another item has an error,
' display a message and cancel the currently edited item.
If bindingGroupInError IsNot Nothing AndAlso bindingGroupInError IsNot container.BindingGroup Then
MessageBox.Show("Please correct the data in error before changing another customer")
container.BindingGroup.CancelEdit()
Return
End If
If container.BindingGroup.UpdateSources() Then
bindingGroupInError = Nothing
MessageBox.Show("Item Saved")
Else
bindingGroupInError = container.BindingGroup
End If
End Sub
Poznámky
Když nastavíte ItemBindingGroup vlastnost, každý kontejner položky získá BindingGroup , který má stejné ValidationRule objekty jako ItemBindingGroup, ale vlastnosti popisující data v vazbách, například Items a BindingExpressions, jsou specifické pro data pro každou položku v objektu ItemsControl. Pokud chcete provádět operace, jako je ověření dat a kontrola chyb u položky, musíte získat přístup ke kontejneru BindingGroup položek.