2015-01-26 2 views
2

내 xaml에는 내부적으로 상단에 몇 가지 컨트롤 (예 : wrappanel 및 Buttons)이있는 ItemControl이 있습니다. 사용자가 버튼을 클릭하면 itemindex를 어떻게 알 수 있습니까?ItemsControl에서 선택된 항목의 인덱스

<ItemsControl ItemsSource="{Binding ConditionList}" AlternationCount="{Binding ConditionList.Count}"> 
    <ItemsControl.ItemTemplate> 
     <DataTemplate> 
      <WrapPanel Background="#FFB1CBCB"> 
      <ComboBox ItemsSource="{Binding DataContext.NodeMembershipFunction, RelativeSource={RelativeSource AncestorType={x:Type ItemsControl}, AncestorLevel=1}}" DisplayMemberPath="_Name" SelectedValue="{Binding Condition, Mode=TwoWay}" SelectedValuePath="_Type"></ComboBox> 
      <Button Content="Remove" Click="Remove_Click" /> 
      </WrapPanel> 
     </DataTemplate> 
    </ItemsControl.ItemTemplate> 
    </ItemsControl> 
+0

명부에있는 품목 색인? ConditionList? – stsur

답변

2

MVT 및 DataTemplates의 전체적인 생각을 깨기 때문에 ItemTemplates에서 이벤트를 많이 사용하지 않는 것이 좋습니다. ConditionList의 각 항목에 구현되는 명령에 해당 단추를 바인딩해야합니다.

코드를 보면 항목을 삭제하려고 시도하는 것으로 나타났습니다. 귀하의 항목을 구현하는 방법을 모르지만 당신의 viewmodel 내부에있는 명령을 사용해야합니다. 당신은 각 품목에 서비스를 통과하고 그 (것)들의 각각이 제거해달라고 요구해달라고하고, 다만 다만 ...

관련 문제