简体   繁体   English

ComboBox 不显示文字

[英]ComboBox does not display the text

i try to retrieve values from Database all controls show the Value except Comboboxs !!我尝试从数据库中检索值,所有控件都显示除了组合框之外的值! im using WPF我正在使用 WPF

<ComboBox Grid.Row="2" BorderBrush="#959595" x:Name="Cmb_Marque" Margin="5" materialDesign:HintAssist.Hint="Marque"  Foreground="WhiteSmoke"   Style="{StaticResource MaterialDesignFloatingHintComboBox}" FontFamily="Champagne &amp; Limousines" FontSize="14" SelectionChanged="Cmb_Marque_SelectionChanged"  >
                <ComboBox.ItemContainerStyle>
                    <Style TargetType="{x:Type ComboBoxItem}">

                        <Setter Property="Foreground" Value="#2196f3"/>
                    </Style>
                </ComboBox.ItemContainerStyle>
            </ComboBox>
            <ComboBox Grid.Row="3" BorderBrush="#959595" x:Name="Cmb_Modele" Margin="5" materialDesign:HintAssist.Hint="Modéle"  Foreground="WhiteSmoke"   Style="{StaticResource MaterialDesignFloatingHintComboBox}" FontFamily="Champagne &amp; Limousines" FontSize="14" IsReadOnly="True" IsEditable="False">
                <ComboBox.ItemContainerStyle>
                    <Style TargetType="{x:Type ComboBoxItem}">

                        <Setter Property="Foreground" Value="#2196f3"/>
                    </Style>
                </ComboBox.ItemContainerStyle>
            </ComboBox>

That's is the c# code那是 c# 代码

if (Config.cn.State == ConnectionState.Closed)
                Config.cn.Open();
            string Query = "Select Vehicule.Matricule,Vehicule.Nchassis,Vehicule.DateAchat,Vehicule.DateMiseService,Vehicule.Prix,Vehicule.Couleur,Vehicule.Carburant,Vehicule.Etat,Vehicule.Kilometrage,Vehicule.IdMarque,Modele.Libelle from Vehicule inner join Modele on Vehicule.IdModele=Modele.IdModele where Vehicule.Matricule=@matricule";

            Config.cmd = new SqlCommand(Query,Config.cn);
            Config.cmd.CommandType = CommandType.Text;
            Config.cmd.Parameters.AddWithValue("matricule",mtc);
            Config.dr = Config.cmd.ExecuteReader();
            while(Config.dr.Read())
            {
                txt_Matricule.Text = Config.dr[0].ToString();
                txt_Chassis.Text = Config.dr[1].ToString();
                Dtp_DateAchat.Text = Config.dr[2].ToString();
                Dtp_miseneservice.Text = Config.dr[3].ToString();
                txt_Prix.Text = Config.dr[4].ToString();
                txt_Couleur.Text = Config.dr[5].ToString();
                Cmb_Carburant.Text= Config.dr[6].ToString();
                Cmb_Disponibilite.Text= Config.dr[7].ToString();
                txt_kilometrage.Text = Config.dr[8].ToString();
                Cmb_Marque.Text = Config.dr[9].ToString();
                Cmb_Modele.Text = Config.dr[10].ToString();


            }
            Config.cn.Close();

that's is the result:这就是结果:

在此处输入图像描述

ComboBox has the ItemsSource that contains the lists of items available and the property SelectValue that indicates which item the user is currently selecting. ComboBox具有包含可用项目列表的ItemsSource和指示用户当前正在选择的项目的属性SelectValue

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM