我有一个包含列表框的组合框。当列表关闭时,我希望能够在组合框或列表框上设置文本。
到目前为止,所有努力都导致文本显示在下拉列表外部的组合框左侧。我希望在关闭时在下拉菜单中设置文本。
我的清单中有 3 项。如果选择(选中)1 我想显示该项目的名称,如果是两个,则显示“多个”,如果 3 显示“全部”。提前感谢您的建议。
最初我只想让文本显示在关闭的组合框中。改变风格没有相关影响。
<TextBlock Margin="4" FontStyle="Italic" FontSize="12" Text="My List" Visibility="Visible">
<TextBlock.Style>
<Style TargetType="{x:Type TextBlock}">
<Style.Triggers>
<DataTrigger Binding="{Binding ElementName=_ReserveStatusListBox, Path=StatusValues.Count}" Value="3">
<Setter Property="Visibility" Value="Visible" />
</DataTrigger>
</Style.Triggers>
</Style>
</TextBlock.Style>
</TextBlock>
<ComboBox
x:Name="_ReservesStatus"
IsSynchronizedWithCurrentItem="True"
Style="{StaticResource {x:Static Theme:Styles.ComboBoxSmall}}"
Width="115"
IsEditable="True"
StaysOpenOnEdit="True">
<ComboBoxItem x:Name="_ListBoxComboBoxItem"
Height="50"
Style="{StaticResource ListBoxComboBoxItem}">
<ListBox
x:Name="_ReserveStatusListBox"
Background="{x:Null}"
BorderBrush="{x:Null}"
ScrollViewer.VerticalScrollBarVisibility="Hidden"
Margin="0"
Height="{Binding Height, ElementName=_ListBoxComboBoxItem, Mode=Default}"
ScrollViewer.CanContentScroll="False"
SelectionMode="Extended"
MultiSelect:MultiSelectorBehaviours.SynchronizedSelectedItems="{Binding SelectedStatusValues}"
ItemsSource="{Binding StatusValues}"
SelectedItem="{Binding StatusValues[0]}"
ItemContainerStyle="{StaticResource Local_MultiListBoxItemSelector}">
<ListBox.ItemTemplate>
<DataTemplate>
<StackPanel
Orientation="Horizontal"
VerticalAlignment="Center">
<CheckBox
IsChecked="{Binding IsSelected, RelativeSource={RelativeSource FindAncestor,AncestorType={x:Type ListBoxItem}}}"
Content="{Binding}"
Style="{StaticResource CheckBoxSmall}"
Foreground="Black"
FontWeight="Bold"
/>
</StackPanel>
</DataTemplate>
</ListBox.ItemTemplate>
</ListBox>
</ComboBoxItem>
<z:EventToCommand.Bindings>
<z:EventBindingCollection>
<z:EventBinding
SourceEvent="{x:Static ComboBox.SelectionChangedEvent}"
TargetCommand="{Binding ApplyFilterCommand}" />
</z:EventBindingCollection>
</z:EventToCommand.Bindings>
</ComboBox>