如何在关闭时在ComboBox ListBox中显示自定义文本

时间:2013-09-08 22:34:04

标签: c# wpf combobox listbox

我有一个包含ListBox的ComboBox。我希望能够在List关闭时在ComboBox或ListBox上设置Text。

到目前为止,所有努力都导致文本显示在下拉外部的ComboBox的左侧。我希望在关闭时将文本设置在下拉列表中。

我的列表中有3个项目。如果选择1(选中),我想显示该项目的名称,如果是2,则显示“多个”,如果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>

0 个答案:

没有答案