catching routedevent from usercontrol

HI all,

i'm creating a usercontrol, and in it i have a slider.  of course, before
making the usercontrol everything exist in the top-level window1.xaml code. 
No problem setting a method to respond to "valuechanged" on the slider.

now that the slider resides in the usercontrol, i'm at a loss on how to
still get the 'valuechanged' event to the top-level.  any thoughts on a way
to do this   do i need to implement a valuechanged method in the code-behind
for the usercontrol and then trigger some custom routed event. Hoping there
will be an easier way.

any help would be appreciate, with some sample code if possible.

make sense

Steve STerling


Answer this question

catching routedevent from usercontrol

  • RossAu42

    thanks for the reply... honestly i did not see either of your replies until today.  I've already gone with the above mentioned solution, but your code helps clarify.  Thank you!

    steve

  • meowbaby7

    All of the events inside the UserControl are contained in the UserControl.

    If you put a Slider in the UserControl, but you want the events to bubble to the "outside world", you'll need to catch the event in your UserControl code and then re-fire it by having another event on your UserControl.

    This behavior is by-design, as tha fact that you have a slider in your control is just an implementation detail. Events that happen on the inside shouldn't be exposed to the outside world unless you expose them explicitly.

  • Pront

    I answered this in the newsgroup, did you not see my reply or was the answer not what you're looking for. Anyway, here's a copy of my reply here as well:

    ----

    The following code in the UserControl's code-behind works for me:


    protected override void OnInitialized(EventArgs e)
    {
       base.OnInitialized(e);
       this.AddHandler(Slider.ValueChangedEvent, new RoutedEventHandler(delegate(object
    sender, RoutedEventArgs args)
       {
          MessageBox.Show("got it!");
       }));
    }

     


    HTH,
    Drew

  • catching routedevent from usercontrol