Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/317.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 更改组合框的前景色复选框_C#_Wpf - Fatal编程技术网

C# 更改组合框的前景色复选框

C# 更改组合框的前景色复选框,c#,wpf,C#,Wpf,我正在尝试更改ComboBoxItem的前景色,但是它不适用,我做错了什么?此外,我正在尝试更改ComboBoxItem上悬停的前景色,但效果并不理想 这是我的xaml: <ComboBox Foreground="Yellow" Name="txtDispatch" HorizontalAlignment="Stretch" VerticalAlignment="Bottom" Margin="0

我正在尝试更改ComboBoxItem的前景色,但是它不适用,我做错了什么?此外,我正在尝试更改ComboBoxItem上悬停的前景色,但效果并不理想

这是我的xaml:

<ComboBox Foreground="Yellow"  Name="txtDispatch" HorizontalAlignment="Stretch" VerticalAlignment="Bottom" Margin="0,0,15,0" Grid.Column="2" Grid.Row="0"   materialDesign:HintAssist.Hint="Select Dispatch"   SelectionChanged="txtDispatch_SelectionChanged">
                    <ComboBox.ItemTemplate >
                        <DataTemplate >
                            <CheckBox  Foreground="Yellow" Name="chkDispatch" Width="220"  Checked="txtDispatch_Checked" Unchecked="txtDispatch_Checked" Content="{Binding Dispatch.id}"  IsChecked="{Binding Check_Status}"  CommandParameter="{Binding Dispatch.id}" />
                        </DataTemplate>
                    </ComboBox.ItemTemplate>
                </ComboBox>


1.
2.
3.
4.
5.
很简单。使用样式

<ComboBox Foreground="Black">
                <ComboBox.Style>
                    <Style TargetType="ComboBox">
                        <Setter Property="ItemContainerStyle">
                            <Setter.Value>
                                <Style TargetType="ComboBoxItem">
                                    <Style.Triggers>
                                        <Trigger Property="IsMouseOver" Value="False">
                                            <Setter Property="Background" Value="White"/>   <!--Optional-->
                                            <Setter Property="Foreground" Value="Red"/>
                                        </Trigger>
                                        <Trigger Property="IsMouseOver" Value="True">
                                            <Setter Property="Background" Value="White"/>   <!--Optional-->
                                            <Setter Property="Foreground" Value="Yellow"/>
                                        </Trigger>
                                    </Style.Triggers>
                                </Style>
                            </Setter.Value>
                        </Setter>
                    </Style>
                </ComboBox.Style>
                
                <!-- Items List-->
                <ComboBoxItem>1</ComboBoxItem>
                <ComboBoxItem>2</ComboBoxItem>
                <ComboBoxItem>3</ComboBoxItem>
                <ComboBoxItem>4</ComboBoxItem>
                <ComboBoxItem>5</ComboBoxItem>
            </ComboBox>