Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6783915
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T16:55:42+00:00 2026-05-26T16:55:42+00:00

I have a form with two ComboBoxes. The second ComboBox holds a list of

  • 0

I have a form with two ComboBoxes. The second ComboBox holds a list of customers. The first ComboBox lets the user choose how they want to search for Customers and see them displayed. Currently, someone has it running different stored procedures for each search type just to change the way it’s displayed in the drop down. I would like to change it so that it chooses a DataTemplate based on the selection of the first drop down.

E.G. If you choose First/Last from the first ComboBox, the customers will display in the second ComboBox drop down as:

John Doe
1234 Fake St. Chandler, Az
(480) 555-2342

If you change it to Last/First, the customers will then show in the drop down as:

Doe, John
1234 Fake St. Chandler, Az
(480) 555-2342

Or if you choose Email, it would display as:

JDoe@gmail.com
John Doe
1234 Fake St. Chandler, Az

I know how to write the templates, but how do I set the second ComboBox.ItemTemplate based on the selection of the first ComboBox? I’d be fine with using Triggers or C# code.

EDIT: Here is one attempt I just tried, but the template doesn’t change. I know the trigger is working because the background turns green.

<UserControl.Resources>
    <DataTemplate x:Key="ComboBoxCustomTemplate">
        <Grid Margin="3 3">
            <Grid.ColumnDefinitions>
                <ColumnDefinition />
                <ColumnDefinition />
            </Grid.ColumnDefinitions>
            <Grid.RowDefinitions>
                <RowDefinition />
                <RowDefinition />
                <RowDefinition />
            </Grid.RowDefinitions>
            <TextBlock Grid.Row="0" Grid.ColumnSpan="2" Text="{Binding Name}" />
            <WrapPanel Grid.Row="1" Orientation="Horizontal">
                <TextBlock Text="Address:" />
                <TextBlock HorizontalAlignment="Left" Foreground="#003366" Margin="3,0,0,0" Text="{Binding Address}" />
            </WrapPanel>
            <WrapPanel Grid.Row="2" Orientation="Horizontal">
                <TextBlock Text="Phone:" />
            <TextBlock HorizontalAlignment="Left" Foreground="#003366" Margin="3,0,0,0" Text="{Binding Telephone}" />
            </WrapPanel>                                
        </Grid>
    </DataTemplate>

    <DataTemplate x:Key="ComboBoxEmailTemplate">
        <Grid Margin="3 3">
            <Grid.ColumnDefinitions>
                <ColumnDefinition />
                <ColumnDefinition />
            </Grid.ColumnDefinitions>
            <Grid.RowDefinitions>
                <RowDefinition />
                <RowDefinition />
                <RowDefinition />
            </Grid.RowDefinitions>
            <TextBlock Grid.Row="0" Grid.ColumnSpan="2" Text="{Binding Email}" />
            <WrapPanel Grid.Row="1" Orientation="Horizontal">
                <TextBlock Text="Address:" />
                <TextBlock HorizontalAlignment="Left" Foreground="#003366" Margin="3,0,0,0" Text="{Binding Address}" />
            </WrapPanel>
            <WrapPanel Grid.Row="2" Orientation="Horizontal">
                <TextBlock Text="Phone:" />
                <TextBlock HorizontalAlignment="Left" Foreground="#003366" Margin="3,0,0,0" Text="{Binding Telephone}" />
            </WrapPanel>
        </Grid>
    </DataTemplate>
</UserControl.Resources>

<ComboBox Name="cbSearchFilter" Padding="5,1" Width="150" Margin="3,3,10,3" SelectionChanged="cbSearchFilter_SelectionChanged" Style="{StaticResource VirtualizingComboBox}">
            <ComboBoxItem Content="Parent Last/First" Tag="LastFirst" />
            <ComboBoxItem Content="Parent First/Last" Tag="FirstLast" />
            <ComboBoxItem Content="Student First/Last" Tag="Student" IsSelected="True" />
            <ComboBoxItem Content="Parent Phone Number" Tag="PhoneNumber"/>
            <ComboBoxItem Content="Parent Email" Tag="Email"/>
        </ComboBox>

<ComboBox Name="cbCustomers"
                SelectedValuePath="FamilyID"
                ItemTemplate="{StaticResource ComboBoxCustomTemplate}"
                Grid.Column="1" Grid.Row="2" IsEditable="True" StaysOpenOnEdit="True"
                KeyboardNavigation.IsTabStop="False" SelectionChanged="rcbCustomers_SelectionChanged" KeyUp="rcbCustomers_KeyUp" KeyDown="rcbCustomers_KeyDown" >
            <ComboBox.Style>
                <Style TargetType="{x:Type ComboBox}" BasedOn="{StaticResource VirtualizingComboBox}">
                    <Style.Triggers>
                        <DataTrigger Binding="{Binding ElementName=cbSearchFilter, Path=SelectedItem.Tag}" Value="Email">
                            <DataTrigger.Setters>
                                <Setter Property="Background" Value="Green" />
                                <Setter Property="ItemTemplate" Value="{StaticResource ComboBoxEmailTemplate}" />
                            </DataTrigger.Setters>
                        </DataTrigger>
                    </Style.Triggers>
                </Style>
            </ComboBox.Style>
        </ComboBox>
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-26T16:55:43+00:00Added an answer on May 26, 2026 at 4:55 pm

    You can use a DataTrigger like this:

    <Style x:Key="ComboBox2Style">
        <Setter Property="ItemTemplate" Value="{StaticResource DefaultTemplate}" />
        <Style.Triggers>
            <DataTrigger Binding="{Binding SelectedValue, ElementName=ComboBox1}" Value="LastFirst">
                <Setter Property="ItemTemplate" Value="{StaticResource LastNameFirstTemplate}" />
            </DataTrigger>
            <DataTrigger Binding="{Binding SelectedValue, ElementName=ComboBox1}" Value="Email">
                <Setter Property="ItemTemplate" Value="{StaticResource EmailTemplate}" />
            </DataTrigger>
        </Style.Triggers>
    </Style>
    

    Edit

    Just noticed the edit to your question. The problem with what you have is the ItemTemplate is defined in the <ComboBox /> tag. According to WPF’s Dependency Property Precedence rules, a value defined directly in the tag overwrites any Styled or Triggered values. To make the Trigged template take effect, set the default ItemTemplate in your ComboBox’s Style

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I currently have two comboboxes on a form. The first combobox contains a list
i have a form that consist of two textfield and one combobox. i want
I have two combo boxes on a form. The first allows the user to
I am using MVC3, EF Model first. I have a form with two DropDownList
I have an input form with two textareas allowing a user to type in
I have two window form applications written in C, one holds a struct consisting
Im using c# .net windows form application. I have two comboboxes A and B
In my windows form i have two combobox and one text box when a
On a form, I have two combobox wich have the same DataSource (their elements
Background I have a Windows Form with the following items: ComboBox TextBox Two Buttons

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.