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

  • Home
  • SEARCH
  • 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 6043155
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T06:52:07+00:00 2026-05-23T06:52:07+00:00

I have a WPF CustomControl that is derived from ComboBox and I’m trying to

  • 0

I have a WPF CustomControl that is derived from ComboBox and I’m trying to figure out how to customize the display of the items. Basically, I want most items to show with normal text but,
depending on the data in each item object, I would like some to display either bold or italic. Normally I do this directly in the XAML, but since it’s a CustomControl I’m a bit at a loss. I would love to be able to just bind it directly in code, but I’m also open to methods that might mean loading in external XAML styles, if you can show me how to do that (I haven’t a clue).

The code below is a basic approximation of the control I’m using but greatly simplified. However, the basic concept of how the data loaded is the same and the data objects themselves are coming from an external source so they can not access the control itself in anyway. The template needs to
just be bound off of the base properties.

public class FormatData
{
    public FormatData() { }
    public string Name { get; set; }
    public bool Bold { get; set; }
    public bool Italic { get; set; }
}

public class FormatDropDown : System.Windows.Controls.ComboBox
{
    public FormatDropDown()
    {
    }

    public void LoadSelection(FormatData[] data)
    {
        try
        {
            this.ItemsSource = data;
            this.DisplayMemberPath = "Name";
        }
        catch (Exception e) { MessageBox.Show(e.Message); ; }
    }
}

The control is populated as follows:

        var data = new FormatData[]{
            new FormatData(){
                Name = "Normal"
            },
            new FormatData(){
                Name = "Bold",
                Bold = true
            },
            new FormatData(){
                Name = "Italic",
                Italic = true
            },
            new FormatData(){
                Name = "BoldItalic",
                Bold = true,
                Italic = true
            },
        };

        fddTest.LoadSelection(data);

Anyone have an idea of how I can achieve this?

  • 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-23T06:52:07+00:00Added an answer on May 23, 2026 at 6:52 am

    How about this:

    public class FormatDropDown : System.Windows.Controls.ComboBox {
        static FormatDropDown() {
            DefaultStyleKeyProperty.OverrideMetadata(typeof(FormatDropDown), new FrameworkPropertyMetadata(typeof(FormatDropDown)));
        }
    
        public void LoadSelection(FormatData[] data) {
            try {
                this.ItemsSource = data;
                this.DisplayMemberPath = "Name";
            } catch (Exception e) { MessageBox.Show(e.Message); ; }
        }
    }
    

    And in the theme file (generic.xaml):

    <Style TargetType="{x:Type local:FormatDropDown}" BasedOn="{StaticResource {x:Type ComboBox}}">
        <Setter Property="ItemContainerStyle">
            <Setter.Value>
                <Style TargetType="ComboBoxItem">
                    <Style.Triggers>
                        <DataTrigger Binding="{Binding Bold}" Value="True">
                            <Setter Property="FontWeight" Value="Bold" />
                        </DataTrigger>
                        <DataTrigger Binding="{Binding Italic}" Value="True">
                            <Setter Property="FontStyle" Value="Italic" />
                        </DataTrigger>
                    </Style.Triggers>
                </Style>
            </Setter.Value>
        </Setter>
    </Style>
    

    So essentially override the DefaultStyleKey for your custom control.

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

Sidebar

Related Questions

I have a WPF ListView which repeats the data vertically. I cannot figure out
I'm trying to have a grid that has items that have a custom layout/feel.
I have a problem with a WPF control that I'm trying to host in
I have a WPF project and I'm trying to setup a NAnt build script
I have several wpf pages with update/delete/add buttons. I want to display to the
I have a WPF control, that has a list of Investors, and in the
I have a WPF ListView that is bound to a BindingList<T>. The binding works
I have a custom control derived from Button: class MyControl : Button{} And suppose,
I have a WPF custom control that sometimes takes a while to render in
I am creating a custom control derived from the one of the Standard WPF

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.