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 6247943
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T12:58:02+00:00 2026-05-24T12:58:02+00:00

I’m newbie to WPF, and maybe ask some stupid question. However. I have a

  • 0

I’m newbie to WPF, and maybe ask some stupid question. However.

I have a tree of my custom class (WidgetDescriptor) derivied classes (MenuDescriptor, LabelDescriptor, ButtonDescriptor, SelectDescriptor). Derived classes provide type-specific properties (SelectDescriptor describes drop-down list and has property, Items, while ButtonDescriptor has properties Text and Image).

WidgetDescriptor has a property Children which is observable collection of WidgetDescriptor instances.

So, application main menu is a tree of MenuDescriptor instances with ButtonDescriptor instances as leaves. Toolbar may contain SelectDescriptor (drop-down box), etc.

I want to know is it possible to map WPF controls to descriptor types with binding?
I want WPF to check WidgetDescriptor derived class type and create specific control? And of these hierarchically, of course.

  • 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-24T12:58:03+00:00Added an answer on May 24, 2026 at 12:58 pm

    There is some built-in functionality for this, every DataTemplate has a DataType, if this is set to the type of your object and the DataTemplate is placed in a Resources dictionary without key it will automatically be used if an object of that type is encoutered in the datasource.

    For your menu you hence can just create a bunch of templates:

    <Menu ItemsSource="{Binding RootList}">
        <Menu.Resources>
            <HierarchicalDataTemplate DataType="{x:Type obj:MenuDescriptor}"
                    ItemsSource="{Binding Children}">
                <!-- ... -->
            </HierarchicalDataTemplate>
            <DataTemplate DataType="{x:Type obj:ButtonDescriptor}">
                <!-- ... -->
            </DataTemplate>
            <!-- ... -->
        </Menu.Resources>
    </Menu>
    

    Use hierarhical ones for trees, they provide an internal ItemsSource for children of the item. It seems redundant to me to have more than one class for a menu tree though, leaves can just be MenuDescriptors as well, albeit without any children (as is the case with normal MenuItems).

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

Sidebar

Related Questions

I have just tried to save a simple *.rtf file with some websites and
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
This could be a duplicate question, but I have no idea what search terms
I don't have much knowledge about the IPv6 protocol, so sorry if the question
I have a .ini file as follows: [playlist] numberofentries=2 File1=http://87.230.82.17:80 Title1=(#1 - 365/1400) Example
link Im having trouble converting the html entites into html characters, (&# 8217;) i
For some reason, after submitting a string like this Jack’s Spindle from a text
I have a jquery bug and I've been looking for hours now, I can't
this is what i have right now Drawing an RSS feed into the php,
I have this code to decode numeric html entities to the UTF8 equivalent character.

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.