, 당신은 (나는 그런 ItemsSource
등의 일반적인 속성을 설정하는 콤보 상자에 대한 공통의 스타일을 만들 수, 10 개 같은 항목 목록 선택 상자,하지만 서로 다른 데이터 소스이 경우
이 바인딩이 모든 항목에 대해 동일하면
SelectedItem
) 실제로 필요하면 양식에 개별 ComboBox를 만듭니다. 당신의 선택 상자의 데이터 소스가 콜렉션에 넣을 수있는 경우
<StackPanel>
<StackPanel.Resources>
<Style TargetType="{x:Type ComboBox}">
<!-- Set the binding to wherever your ItemsSource resides. In this
case,I'm binding to a static class called Lists and a static
property called ComboBoxItems -->
<Setter Property="ItemsSource"
Value="{Binding Source={x:Static local:Lists.ComboBoxItems}}" />
<!-- Only use this setter if your binding is the same everywhere -->
<Setter Property="SelectedItem" Value="{Binding SelectedItem}" />
</Style>
</StackPanel.Resources>
<ComboBox DataContext="{Binding Item1}" />
<ComboBox DataContext="{Binding Item2}" />
<ComboBox DataContext="{Binding Item3}" />
<ComboBox DataContext="{Binding Item4}" />
<ComboBox DataContext="{Binding Item5}" />
<ComboBox DataContext="{Binding Item6}" />
<ComboBox DataContext="{Binding Item7}" />
<ComboBox DataContext="{Binding Item8}" />
<ComboBox DataContext="{Binding Item9}" />
<ComboBox DataContext="{Binding Item10}" />
</StackPanel>
는 물론, 그들이 것이 바람직하다 당신은 선택 상자
<ItemsControl ItemsSource="{Binding SelectedItems}">
<ItemsControl.ItemTemplate>
<DataTemplate>
<ComboBox SelectedItem="{Binding }"
ItemsSource="{Binding Source={x:Static local:Lists.ComboBoxItems}}" />
</DataTemplate>
</ItemsControl.ItemTemplate>
</ItemsControl>
감사합니다 레이첼 - '내가 당신을 이해한다면, 당신은 10 콤보 상자가 있습니다. 동일한 항목 목록이지만 다른 데이터 소스 '- 예, 각 콤보 상자는'SelectedItems 'ObservableCollection ..의 별도 항목에 바인딩됩니다. 그러나'ComboBoxes 용 DataSource를 컬렉션에 넣을 수 있는지 '에 대한 대답도 예 .. 혼란스럽게 유감스럽게 생각합니다. ItemsControl을 권하고 싶습니다. –
@ Joe.Net 예, 당신의 상황에서'ItemsControl'을 추천합니다. 원래 질문에서 말했던 내용에 따라'ItemsControl.ItemCollection'을'SelectedItems'에 바인드하고 ComboBox에 ComboBox'SelectedItem = "{Binding}"'을 설정하면 선택한 항목을에있는 항목에 바인딩 할 수 있습니다. 컬렉션. ItemTemplate을 사용하고 있으므로 ComboBox에 대해 별도의 스타일을 만들 필요가 없습니다. – Rachel
우수, Thanks Rachel –