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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T23:16:17+00:00 2026-05-23T23:16:17+00:00

How to programmatically add an event handler to an object which exists only in

  • 0

How to programmatically add an event handler to an object which exists only in ControlTemplate of another object?

I work with Silverlight 4. I want to use control ColorSelector from a third party DLL (Liquid). It looks like combobox, but is implemented differently. (It was probably made for and older version of Silverlight when there was no system ComboBox.) The class ColorSelector derives from ContentControl, and its look is implemented using ControlTemplate defined in a xaml file.

In the fact it is a control which looks like combo box, but programatically its object doesn’t derive from combo box. And now I am stuck, because I’d like to programatically access the combo box object I can see on screen. Normally if it was a real standard ComboBox, I would use events DropDownOpened and DropDownClosed to know when the box is shown and hidden respectively. But this color selector doesn’t provide these events. But it uses a ControlTemplete which defines the look of the ColorSelector as a DropDown object. That DropDown class is another class from the same dll, and its look is also defined by its ControlTemplate and that is the place where that mysterious combobox-like look is based. And I am now totally confused by all this.

How can I programatically access these visual controls which I can see on screen but aren’t directly present in the code? Here is one simple example:

class ColorSelector : LiquidControl
class LiquidControl : ContentControl

<Style TargetType="local:ColorSelector">
    <Setter Property="Template">
        <Setter.Value>
            <ControlTemplate TargetType="local:ColorSelector">
                <local:DropDown x:Name="RootElement">
                .....
                </local:DropDown>
            </ControlTemplate>
        </Setter.Value>
    </Setter>
</Style>

class DropDown : LiquidControl

<Style TargetType="local:DropDown">
    <Setter Property="Template">
        <Setter.Value>
            <ControlTemplate TargetType="local:DropDown">
                <Grid x:Name="RootElement">
                    <Button x:Name="ElementButton">
                </Grid>
            </ControlTemplate>
        </Setter.Value>
    </Setter>
</Style>

Now I create a new ColorControl in my code (new ColorControl()) and then I’d like to access that button defined in template of DropDown. How to do it?

  • 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-23T23:16:18+00:00Added an answer on May 23, 2026 at 11:16 pm

    I have found a solution to my problem with change of the original DLL. It is based on the answer given by anivas. I put this code to DropDown.OnApplyTemplate:

            ElementPopup.Opened += (s, ea) => { DropDownOpened(this, ea); };
            ElementPopup.Closed += (s, ea) => { DropDownClosed(this, ea); };
    

    These two events signal when the combobox is opened and closed respectively. (Combobox is implemented using those templates I didn’t understand before, there is Popup object to display an opened combobox.)

    Then, analogically, I added similar code to ColorSelector.OnApplyTemplate:

            _dropDown.DropDownOpened += (s, ea) => { DropDownOpened(this, ea); };
            _dropDown.DropDownClosed += (s, ea) => { DropDownClosed(this, ea); };
    

    Now I have got these two new events in ColorSelector, which signal when its being opened or closed. And that is what I wanted.

    Thanks to anivas! His answer didn’t work itself but it showed me where to start. (If I derived the ColorSelector class, I lost its template and routed events. And also it uses DropDown which must be changed somehow too.)

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

Sidebar

Related Questions

I am trying to figure out how to programmatically add an event handler to
How do I programmatically add user permissions to a list in Sharepoint? I want
Does anyone know how to programmatically remove/add the checked and unchecked event on WPF
How do I add rows programmatically to a DataGridTable in C#? When the user
In my project I programmatically create a web part page and add a web
Is there a way to programmatically interface with iTunes to add new playlists or
I'm programmatically adding ToolStripButton items to a context menu. That part is easy. this.tsmiDelete.DropDownItems.Add(The
In my Silverlight 3 user control I am showing a basic DataGrid control. I
I wrote a custom Control (an auto-complete TextBox (below)) in which a ContextMenuStrip is
The Scenario: I have an ASP.Net webpage which I intend to use for letting

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.