SimpleStyles vs Custom Styles RRS feed

  • Question

  • Here is my simple scenario:

    When I drag drop a SimpleListBox control (in which the style obviously comes from the SimpleStyles.xaml resource dictionary), in Blend 3 I am able to right-click it and add a SimpleListBoxItem from the context-menu, which is the perfect behavior.

    Now I use my own listbox with its style applied (called CustomListBox), when I right-click it, instead of getting my CustomListBoxItem in the context-menu, I always get the regular ListBoxItem.

    How can I have the context-menu show my CustomListBoxItem instead of ListBoxItem ???
    Is there something I'm missing in my custom Resource Dictionary that links the parent and child styles ?

    Thank you !

    P.S. I forgot to mention that my custom styles and controls are coming from an assembly, therefore I'm referencing the CustomListBox as local:CustomListBox in my XAML. Can this cause the problem?
    Wednesday, November 18, 2009 6:51 PM

All replies

  • Hi.

    Not sure if this is the right answer, but try this: Scope back up one level (up arrow beside UserControl), right click on list box item, then Edit Template - Edit a copy.

    Hope this helps.

    Thursday, November 19, 2009 4:03 PM
  • Sorry that doesn't work because I'm not in a template. I'm in the main window of my small application. I simply added my own TabControl (inherited from System.Windows.Controls.TabControl) and right-clicked.
    Tuesday, December 15, 2009 7:30 PM
  • Still wondering if anyone knows to have Blend show CustomListBoxItem in the menu instead of SimpleListBoxItem or ListBoxItem...
    Wednesday, December 16, 2009 2:49 PM
  • Did you try implementing the GetContainerForItemOverride() ? i.e.

            protected override System.Windows.DependencyObject GetContainerForItemOverride()


                DependencyObject doRet = new CustomListBoxItem();


                return doRet;


    Wednesday, December 16, 2009 11:29 PM
  • Just tried it, but no luck.

    Thanks for the reply!   :)

    Thursday, December 17, 2009 4:16 PM
  • Just bumping the message one more time to see if anyone else has any ideas....
    Wednesday, December 30, 2009 2:28 PM
  • I don't know if Blend will adjust its UI intelligently to know that a parent container requests specific types of children.  Do you absolutely need to do this from the designer, i.e. do you need a visual representation of the children in Blend?  Is it something that can be done via code-behind instead?  Are you doing this to prevent the GUI designer from touching code?
    Wednesday, December 30, 2009 4:11 PM
  • I don't absolutely need it, but it would be a nice enough feature to have for custom children. I guess I'll have to let this go. But then how come it works with the Simple Styles? It is possible that the Blend team made it work only for the Simple Controls?
    Wednesday, December 30, 2009 4:34 PM