WPF组合框:只有第一个项目可以编辑

时间:2016-12-03 13:20:05

标签: c# wpf combobox

只有Combobox中的第一项(selectedIndex = 0)才可以编辑。我已经知道了。但问题是所选文本没有突出显示。

任何帮助将不胜感激!

Code
<Window.Resources>

    <Style x:Key="ComboBoxStyle" TargetType="{x:Type ComboBox}">
        <Setter Property="IsEnabled" Value="True"></Setter>
        <Style.Triggers>
            <DataTrigger Binding="{Binding Path=SelectedIndex, ElementName=comboBox1}" Value="0">
                <Setter Property="ComboBox.IsEditable" Value="True" />
            </DataTrigger>
        </Style.Triggers>
    </Style>

    <Style x:Key="FirstItem" TargetType="{x:Type ListBoxItem}">
        <Style.Triggers>
            <Trigger Property="ComboBox.AlternationIndex" Value="0" >
                <Setter Property="Background" Value="{DynamicResource {x:Static SystemColors.ControlBrushKey}}"/>
                <Setter Property="FontWeight" Value="Normal"/>
                <Setter Property="FontStyle" Value="Italic"/>
                <Setter Property="FontFamily" Value="SEGOEWP"/>
                <Setter Property="FontSize" Value="15"/>
                <Setter Property="Foreground" Value="Gray"/>
                <Setter Property="Opacity" Value="1"/>
                <Setter Property="TextBlock.TextTrimming" Value="WordEllipsis"/>
            </Trigger>
        </Style.Triggers>

        <Style.Resources>
            <SolidColorBrush x:Key="{x:Static SystemColors.HighlightBrushKey}" Color="Green"/>
        </Style.Resources>

    </Style>
</Window.Resources>

<StackPanel >
    <ComboBox Name="comboBox1" Style="{StaticResource ComboBoxStyle}" Width="100" Height="38"   
      AlternationCount="500" ItemsSource="{Binding Items}"
      ItemContainerStyle="{StaticResource FirstItem}"
              SelectedItem="{Binding SelectedItem}"
              SelectedIndex="{Binding SelectedIndex}"
              IsTextSearchEnabled="false"
              Text="{Binding NewItem, UpdateSourceTrigger=LostFocus}">

        <ComboBox.InputBindings>
            <KeyBinding Command="{Binding LoginCMD}" Key="Return" />
        </ComboBox.InputBindings>
    </ComboBox>
</StackPanel>

0 个答案:

没有答案