2016-10-15 15 views
1

でコンボボックスの項目の追加情報を追加します。まず、これは背後に私のコードです:は異なる色

conn.Open(); 
DataTable data = new DataTable(); 
string sql = "SELECT * FROM itemsTbl"; 
SQLiteCommand command = new SQLiteCommand(sql, conn); 
SQLiteDataAdapter adapter = new SQLiteDataAdapter(command); 
adapter.Fill(data); 
cmb_items.ItemsSource = data.DefaultView; 
cmb_items.DisplayMemberPath = "item_description"; 
cmb_items.SelectedValuePath = "item_id"; 
conn.Close(); 

そして、これは私のXAMLです:

<ComboBox x:Name="cmb_items" 
    VerticalAlignment="Top" VerticalContentAlignment="Center" 
    FontSize="14" 
    Foreground="#666" 
    Height="30" 
    Margin="20,20,20,10" 
    IsEditable="True" 
    ItemsSource="{Binding}" 
    TextSearch.Text="{Binding Path=item_description}" /> 

それは罰金や作業ですが、私は追加したいと思いますコンボボックスの項目に関するいくつかの情報は、ユーザーが既に在庫があるかどうかを知っているか、またはパックやPCなどの情報であることがわかります。可能であれば、ゼロ在庫の色を赤に変更します。

これは私の現在のコンボボックスである:

ComboBox1

これが私の目標(フォトショップ)である:私はコンボボックスの項目に余分な情報が必要

enter image description here

が、場合ユーザーがアイテムをクリックすると、次のようにitem_descriptionだけが表示されます。

enter image description here

私は正直にここで何をすべきかわからない、私はコンボボックスを追加しようとしました。アイテムテンプレートを選択すると "System.Data.DataRowView"を示します。また、コンボボックスも検索可能です。私は私のアプローチを変更し、ループを介して項目を追加する必要がありますか?私はちょっとwpfに新しい、私はwpfを前に試みたが、忙しい仕事のために停止したので、どんな助けも本当にありがとう!あなたはItemTemplateにとDataTriggerを使用することができ、余分な情報を表示するために

答えて

0

1.In順序:あなたはDataTemplateSelectorを使用することができ、他の項目から選択したアイテムに異なる表示を持っている

 <ComboBox.ItemTemplate> 
      <DataTemplate DataType="wpfApplication1:Item"> 
       <StackPanel Orientation="Horizontal"> 
        <TextBlock Text="{Binding item_id}"/> 
        <TextBlock Text="{Binding item_description}" Margin="300,0,0,0"> 
         <TextBlock.Style> 
          <Style> 
           <Style.Triggers> 
            <DataTrigger Binding="{Binding item_description}" Value="0"> 
             <Setter Property="TextBox.Foreground" Value="Red"/> 
            </DataTrigger> 
           </Style.Triggers> 
          </Style> 
         </TextBlock.Style> 
        </TextBlock> 
       </StackPanel> 
      </DataTemplate> 
     </ComboBox.ItemTemplate> 

2.In順:https://stackoverflow.com/a/33421573/3955716

+1

それはありがとう男! – Gen

関連する問題