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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 18, 20262026-05-18T00:10:40+00:00 2026-05-18T00:10:40+00:00

I am trying to create a Blend behavior related to ComboBoxes. In order to

  • 0

I am trying to create a Blend behavior related to ComboBoxes. In order to get the effect I want, the ItemsPanel of the ComboBox has to have a certain element added to it. I don’t want to do this in every ComboBox that uses the behavior, so I want the Behavior to be able to inject the ItemsPanelTemplate programmatically. However, I can’t seem to find a way to do this. ItemsPanelTemplate does not seem to have a property/method that lets me set the visual tree. WPF ItemsPanelTemplate has the VisualTree but Silverlight does not.

Basically, what is the programmatic equivalent of this XAML?

    <ComboBox>
        <ComboBox.ItemsPanel>
            <ItemsPanelTemplate>
                <StackPanel/>
            </ItemsPanelTemplate>
        </ComboBox.ItemsPanel>
    </ComboBox>

Edit:
Okay apparently that is not an easy question, so I started a bounty and I’m going to give some more background in case there is another way to go about this. I want to provide keyboard support for the Silverlight ComoboBox. Out of the box it only supports the up and down arrows but I also want it to work so that when the user hits a letter, the ComboBox jumps to the first item of that letter, similar to how ComboBoxes work in a browser or Windows app.

I found this blog post, which got me half way. Adapting that behavior code, the ComboBox will change selection based on letter input. However, it does not work when the ComboBox is opened. The reason for this, according to this blog post is that when the ComboBox is opened, you are now interacting with its ItemsPanel and not the ComboBox itself. So according to that post I actually need to add a StackPanel to the ItemsPanelTemplate and subscribe to the StackPanel’s KeyDown event, in order to take action when the ComboBox is opened.

So that is what prompted my question of how to get a StackPanel into the ItemsPanelTemplate of a ComboBox, from a behavior. If that is not possible, are there alternative ways of getting this to work? Yes, I know I could go to each ComboBox in the application and add a StackPanel and the event. But I want to do this through a behavior so that I don’t have to modify every ComboBox in the app, and so I can reuse this logic across applications.

AnthonyWJones’ answer below using XamlReader gets me part way, in that I can create the StackPanel and get it into the template. However, I need to be able to get at that SP programmatically in order to subscribe to the event.

  • 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-18T00:10:41+00:00Added an answer on May 18, 2026 at 12:10 am

    I think, best way for you – extend combobox functionality not via behavior but using inheritance.
    So, you can create own control MyComboBox:ComboBox. Create style for it – get default ComboBox Style
    here

    And write instead (look for ScrollViewer by name):

    < ScrollViewer x:Name="ScrollViewer" BorderThickness="0" Padding="1" >

       < ItemsPresenter />
    

    < /ScrollViewer >

    this

    < ScrollViewer x:Name="ScrollViewer" BorderThickness="0" Padding="1" >

    < StackPanel x:Name="StackPanel" >
    
       < ItemsPresenter />
    
    < /StackPanel >
    

    < /ScrollViewer >

    This StackPanel you can get in code:

    public class MyComboBox: ComboBox{

        public CM()
        {
            DefaultStyleKey = typeof (MyComboBox);
        }
        public override void OnApplyTemplate()
        {
            base.OnApplyTemplate();
            StackPanel stackPanel = (StackPanel)GetTemplateChild("StackPanel");
            stackPanel.KeyUp += (s, e) => { /*do something*/ };
        }
    

    }

    Inheritance is more powerful. It’s allow work with template elements.
    If you decided to inject ItemsPanel, you must understand that:

    1)it’s impossible from code with keeping reference on injected panel.
    2)to get reference to injected panel, this panel must registered itself in some storage, e.g.

    < ComboBox>

       < ComboBox.ItemsPanel>
    
           < ItemsPanelTemplate>
    
               < StackPanel>
    
                 < i:Interaction.EventTriggers>
    
                   < i:EventTrigger EventName="Loaded">
    
                      < RegisterMyInstanceInAccessibleFromCodePlaceAction/>
    
                   < /i:EventTrigger>
    
                 < /i:Interaction.EventTriggers>
    
              < /StackPanel>
    
           < /ItemsPanelTemplate>
    
       < /ComboBox.ItemsPanel>
    

    < /ComboBox>

    Good luck!

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

Sidebar

Related Questions

I have been trying to create a user control library which simply has styled
Trying to create a new Dedicated Cache Role in Windows Azure but get the
I am trying to create a simple ray tracer. I have a perspective view
I am trying to create a TreeView from the Silverlight TreeView control. I have
I'm a developer who's trying to get the hang of Blend. I've always used
I am trying to create a extension from an existing view where I have
I am trying to create a composite DataContext for a UserControl. Basically I have
I'm trying to create a custom radiobutton which has images for the pressed state,
I am trying to create a concatenation of multiple images into one, but have
I'm new to WPF and I'm trying to create an UserControl which will have

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.