我有多列组合框但我想在很多地方使用这些组合框。所以我想我需要创建组合框用户控件。但是问题是每个组合框的itemsource都不一样。
目前我的多列组合框
<ComboBox Grid.Row="0"
Grid.Column="1"
Margin="2"
Width="150"
x:Name="cboemployee"
IsEditable="True"
DisplayMemberPath="EmployeeID"
SelectedValuePath="EmployeeID"
ItemsSource="{Binding EmployeeList}">
<ComboBox.ItemContainerStyle>
<Style TargetType="{x:Type ComboBoxItem}" BasedOn="{StaticResource MetroComboBoxItem}">
<Setter Property="Template">
<Setter.Value>
<ControlTemplate>
<Grid Width="400" x:Name="gd">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="100"/>
<ColumnDefinition Width="300"/>
</Grid.ColumnDefinitions>
<TextBlock Margin="2" Grid.Column="0" Text="{Binding EmployeeID}"/>
<TextBlock Margin="2" Grid.Column="1" Text="{Binding EmployeeName}"/>
</Grid>
<ControlTemplate.Triggers>
<Trigger Property="ComboBoxItem.IsSelected" Value="True">
<Setter TargetName="gd" Property="Background" Value="{StaticResource AccentBaseColorBrush}"></Setter>
<Setter TargetName="gd" Property="TextElement.Foreground" Value="White"></Setter>
</Trigger>
<Trigger Property="ComboBoxItem.IsMouseOver" Value="True">
<Setter TargetName="gd" Property="Background" Value="{StaticResource AccentColorBrush}"></Setter>
<Setter TargetName="gd" Property="TextElement.Foreground" Value="White"></Setter>
</Trigger>
</ControlTemplate.Triggers>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
</ComboBox.ItemContainerStyle>
</ComboBox>
我不确定我是否需要自定义组合框或组合框用户控件,请让我知道哪个最适合我的要求并绑定不同的项目来源?