Выбранное значение в поле со списком перед цветом XAML WPF

Я хочу изменить цвет переднего плана для выбранного значения на белый в моем поле со списком. Есть ли способ выполнить действие желания. Ура

ComboBox

Стиль моего ComboBox:

<ResourceDictionary x:Class="Kororder.ApplicationDesign.Styles.MyCombo"
         xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
         xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">

<Color x:Key="GrayColor_">#FF928B81</Color>
<Color x:Key="LightGrayColor_">#FFC3C3C3</Color>
<Color x:Key="LightLightGrayColor_">#FFF1F1F1</Color>
<SolidColorBrush x:Key="GrayColor" Color="{StaticResource GrayColor_}"/>
<SolidColorBrush x:Key="LightGrayColor" Color="{StaticResource LightGrayColor_}"/>
<SolidColorBrush x:Key="LightLightGrayColor" Color="{StaticResource LightLightGrayColor_}"/>

<Color x:Key="BlueColor_">#0073b0</Color>
<Color x:Key="DarkBlueColor_">#FF004165</Color>
<Color x:Key="LightBlueColor_">#FFa4ddfa</Color>
<SolidColorBrush x:Key="BlueColor" Color="{StaticResource BlueColor_}" />
<SolidColorBrush x:Key="DarkBlueColor" Color="{StaticResource DarkBlueColor_}" />
<SolidColorBrush x:Key="LightBlueColor" Color="{StaticResource LightBlueColor_}" />

<SolidColorBrush x:Key="Foreground" Color="Black"/>
<SolidColorBrush x:Key="ForegroundWhite" Color="White"/>


<Style x:Key="LightGrayBox" TargetType="{x:Type Border}">
    <Setter Property="Background" Value="White"/>
    <Setter Property="BorderThickness" Value="1"/>
    <Setter Property="SnapsToDevicePixels" Value="True"/>
    <Setter Property="BorderBrush" Value="{StaticResource LightGrayColor}" />
</Style>


<Style x:Key="ComboBoxToggleButton" TargetType="{x:Type ToggleButton}">
    <Setter Property="Template">
        <Setter.Value>
            <ControlTemplate TargetType="ToggleButton">
                <Grid>
                    <Grid.ColumnDefinitions>
                        <ColumnDefinition/>
                        <ColumnDefinition Width="20"/>
                    </Grid.ColumnDefinitions>
                    <Border x:Name="Border" Style="{DynamicResource LightGrayBox}" Grid.ColumnSpan="2" />
                    <Path x:Name="Arrow" Grid.Column="1" Opacity="0.6" Fill="{StaticResource GrayColor}" HorizontalAlignment="Center" VerticalAlignment="Center" Data="M 0 0 L 4 4 L 8 0 Z"/>
                </Grid>
                <ControlTemplate.Triggers>
                    <Trigger Property="ToggleButton.IsMouseOver" Value="true">
                        <Setter TargetName="Arrow" Property="Opacity" Value="1" />
                        <Setter TargetName="Arrow" Property="Fill" Value="{StaticResource BlueColor}" />
                        <Setter TargetName="Border" Property="BorderBrush" Value="{DynamicResource BlueColor}"/>
                    </Trigger>
                    <Trigger Property="ToggleButton.IsChecked" Value="true">
                        <Setter TargetName="Arrow" Property="Opacity" Value="1" />
                        <Setter TargetName="Arrow" Property="Fill" Value="{StaticResource BlueColor}" />
                    </Trigger>
                    <Trigger Property="IsEnabled" Value="False">
                        <Setter TargetName="Border" Property="Style" Value="{StaticResource LightGrayBox}" />
                        <Setter Property="Foreground" Value="{StaticResource GrayColor}"/>
                        <Setter TargetName="Arrow" Property="Fill" Value="{StaticResource GrayColor}" />
                    </Trigger>
                </ControlTemplate.Triggers>
            </ControlTemplate>
        </Setter.Value>
    </Setter>
</Style>

<Style x:Key="ComboBoxToggleButtonActive" TargetType="{x:Type ToggleButton}">
    <Setter Property="Template">
        <Setter.Value>
            <ControlTemplate TargetType="ToggleButton">
                <Grid>
                    <Grid.ColumnDefinitions>
                        <ColumnDefinition/>
                        <ColumnDefinition Width="20"/>
                    </Grid.ColumnDefinitions>
                    <Border x:Name="Border" Grid.ColumnSpan="2" Background="{DynamicResource BlueColor}" />
                    <Path x:Name="Arrow" Grid.Column="1" Opacity="1" Fill="White" HorizontalAlignment="Center" VerticalAlignment="Center" Data="M 0 0 L 4 4 L 8 0 Z"/>
                </Grid>
                <ControlTemplate.Triggers>
                    <Trigger Property="IsFocused" Value="true">
                        <Setter TargetName="Border" Property="Background" Value="{DynamicResource BlueColor}" />
                        <Setter TargetName="Border" Property="BorderBrush" Value="White"/>
                        <Setter Property="Foreground" Value="White" />
                    </Trigger>
                </ControlTemplate.Triggers>
            </ControlTemplate>
        </Setter.Value>
    </Setter>
</Style>

<ControlTemplate x:Key="ComboBoxTextBox" TargetType="TextBox">
    <Border x:Name="PART_ContentHost" Focusable="False" Background="{TemplateBinding Background}" />
</ControlTemplate>



<Style x:Key="StandardComboBox" TargetType="{x:Type ComboBox}">
    <Setter Property="Foreground" Value="{StaticResource Foreground}"/>
    <Setter Property="Height" Value="25"/>
    <Setter Property="HorizontalAlignment" Value="Left"/>
    <Setter Property="IsEditable" Value="True" />
    <Setter Property="OverridesDefaultStyle" Value="true"/>
    <Setter Property="SnapsToDevicePixels" Value="true"/>
    <Setter Property="ScrollViewer.HorizontalScrollBarVisibility" Value="Auto"/>
    <Setter Property="ScrollViewer.VerticalScrollBarVisibility" Value="Auto"/>
    <Setter Property="ScrollViewer.CanContentScroll" Value="true"/>
    <Setter Property="VerticalAlignment" Value="Top"/>
    <Setter Property="Width" Value="120"/>
    <Setter Property="IsSelected" Value="{Binding IsKeyboardFocusWithin, RelativeSource={RelativeSource Self}, Mode=OneWay}" />
    <Setter Property="Template">
        <Setter.Value>
            <ControlTemplate TargetType="ComboBox">
                <Grid GotFocus="OnGotFocus">
                    <ToggleButton Name="ToggleButton" Style="{StaticResource ComboBoxToggleButton}" Grid.Column="2" Focusable="false" ClickMode="Press"
                      IsChecked="{Binding Path=IsDropDownOpen, Mode=TwoWay, RelativeSource={RelativeSource TemplatedParent}}" />
                    <ContentPresenter Name="ContentSite" IsHitTestVisible="False" Content="{TemplateBinding SelectionBoxItem}" ContentTemplate="{TemplateBinding SelectionBoxItemTemplate}" 
                                      ContentTemplateSelector="{TemplateBinding ItemTemplateSelector}" Margin="3,3,23,3" VerticalAlignment="Center" HorizontalAlignment="Left" />
                    <TextBox x:Name="PART_EditableTextBox" 
                             CaretBrush="{DynamicResource ForegroundWhite}"
                             Style="{x:Null}" 
                             Template="{StaticResource ComboBoxTextBox}" 
                             HorizontalAlignment="Left" 
                             VerticalAlignment="Center" 
                             Margin="3,3,23,3" 
                             Focusable="True" 
                             Background="Transparent" 
                             Foreground="{StaticResource Foreground}" 
                             Visibility="Hidden" 
                             IsReadOnly="{TemplateBinding IsReadOnly}"/>
                    <Popup VerticalOffset="-1" SnapsToDevicePixels="True" Name="Popup" Placement="Bottom" IsOpen="{TemplateBinding IsDropDownOpen}" AllowsTransparency="True"  Focusable="False" PopupAnimation="Fade">
                        <Grid Name="DropDown" SnapsToDevicePixels="True" MinWidth="{TemplateBinding ActualWidth}" MaxHeight="200">
                            <Border x:Name="DropDownBorder" Style="{DynamicResource LightGrayBox}"/>
                            <ScrollViewer SnapsToDevicePixels="True">
                                <StackPanel IsItemsHost="True" KeyboardNavigation.DirectionalNavigation="Contained" />
                            </ScrollViewer>
                        </Grid>
                    </Popup>
                </Grid>
                <ControlTemplate.Triggers>
                    <Trigger Property="HasItems" Value="false">
                        <Setter TargetName="DropDownBorder" Property="MinHeight" Value="20"/>
                    </Trigger>
                    <Trigger Property="IsEnabled" Value="false">
                        <Setter Property="Foreground" Value="{StaticResource GrayColor}"/>
                    </Trigger>
                    <Trigger Property="IsGrouping" Value="true">
                        <Setter Property="ScrollViewer.CanContentScroll" Value="false"/>
                    </Trigger>
                    <Trigger Property="IsSelected" Value="True">
                        <Setter TargetName="ToggleButton" Property="Style" Value="{StaticResource ComboBoxToggleButtonActive}" />
                    </Trigger>
                    <Trigger Property="IsEditable" Value="true">
                        <Setter Property="IsTabStop" Value="false"/>
                        <Setter TargetName="PART_EditableTextBox" Property="Visibility" Value="Visible"/>
                        <Setter TargetName="ContentSite" Property="Visibility" Value="Hidden"/>
                    </Trigger>
                </ControlTemplate.Triggers>
            </ControlTemplate>
        </Setter.Value>
    </Setter>
    <Style.Resources>
        <Style TargetType="ComboBoxItem">
            <Setter Property="SnapsToDevicePixels" Value="true"/>
            <Setter Property="OverridesDefaultStyle" Value="true"/>
            <Setter Property="HorizontalContentAlignment" Value="Left" />
            <Setter Property="VerticalContentAlignment" Value="Center" />
            <Setter Property="Template">
                <Setter.Value>
                    <ControlTemplate TargetType="ComboBoxItem">
                        <Border Name="Border" Padding="2" SnapsToDevicePixels="true" BorderThickness="1">
                            <ContentPresenter />
                        </Border>
                        <ControlTemplate.Triggers>
                            <Trigger Property="IsHighlighted" Value="true">
                                <Setter TargetName="Border" Property="Background" Value="{DynamicResource BlueColor}"/>
                                <Setter TargetName="Border" Property="Padding" Value="2,3,2,3" />
                                <Setter Property="Foreground" Value="White" />
                            </Trigger>
                        </ControlTemplate.Triggers>
                    </ControlTemplate>
                </Setter.Value>
            </Setter>
        </Style>
    </Style.Resources>
</Style>


person Nav Khan    schedule 26.03.2013    source источник
comment
Решенная проблема: textuploader.com/?p=6&id=mQ9u   -  person Nav Khan    schedule 26.03.2013


Ответы (1)


Вы должны перейти на сайт msdn и получить шаблон элемента управления по умолчанию для поля со списком. После этого вы используете его в своем проекте и меняете в зависимости от ваших потребностей. Здесь: Пример шаблона элемента управления ComboBox

Либо так, либо используйте Expression Blend

person Santux    schedule 26.03.2013
comment
Следующее изображение является результатом моего xaml. i.stack.imgur.com/L8jpj.png Немного сложно добиться желаемого результат из вашего шаблона MSDN. МОЙ КОД XAML: textuploader.com/?p=6&id=yWl7a - person Nav Khan; 26.03.2013
comment
в части ‹TextBox x:Name=PART_EditableTextBox (...) измените значение переднего плана с {StaticResource Foreground} на White, я думаю, это то, что вы хотите - person Santux; 26.03.2013
comment
Текст меняет свой цвет на белый. И на LostFocus и фон, и передний план белые :) Я хочу белый передний план на Onfocus, но черный на потерянном фокусе. - person Nav Khan; 26.03.2013
comment
Вы пробовали использовать Expression Blend? Это довольно крутой инструмент для редактирования стилей управления! Мне пришлось бы более подробно изучить xaml, чтобы получить изменения, которые вы притворяетесь, поскольку я тоже новичок во всем этом;) - person Santux; 26.03.2013
comment
Да, я тоже использую Blend. К сожалению, там тоже не найдено решения. В любом случае спасибо за помощь :) - person Nav Khan; 26.03.2013