ItemsControl.ItemBindingGroup 속성

정의

BindingGroup 의 각 항목에 복사되는 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

속성 값

BindingGroup 의 각 항목에 복사되는 ItemsControl입니다.

특성

예제

다음 예제에서는 여러 고객을 입력 하 고 각 고객에 게는 영업 담당자를 할당 하 라는 메시지는 애플리케이션의 일부 이며 그런 다음 영업 담당자와 고객 동일한 지역에 속해 있는지를 확인 합니다. 이 예제에서는 의 ItemsControlItemBindingGroup 설정하여 , 가 AreasMatch각 항목의 ValidationRule유효성을 검사합니다. 예제에서는 Label 유효성 검사 오류를 표시 하는 합니다. ContentLabel 가 속성에서 Validation.ValidationAdornerSiteForProperty 가져오는 에 ValidationError 바인딩됩니다. 값 Validation.ValidationAdornerSiteForProperty 은 오류가 있는 항목 컨테이너입니다.

<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"/>

다음 예제에서는 항목 컨테이너를 가져오고 컨테이너의 BindingGroup 를 호출 UpdateSources 하여 데이터의 유효성을 검사합니다. 의 가 아닌 항목 컨테이너의 BindingGroup에서 메서드를 호출하여 데이터의 유효성을 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

설명

설정 하는 경우는 ItemBindingGroup 속성인 각 항목 컨테이너를 가져옵니다을 BindingGroup 는 동일 ValidationRule 개체로 ItemBindingGroup, 하지만 같은 바인딩에 데이터를 설명 하는 속성 ItemsBindingExpressions는 각 항목에 대 한 데이터에 특정 된 ItemsControl합니다. 항목 컨테이너의 액세스 해야 BindingGroup 수행 하려면 작업 유효성 검사와 같은 데이터 및 항목에서 오류를 확인 합니다.

적용 대상