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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T12:57:51+00:00 2026-05-30T12:57:51+00:00

I have wpf user control <StackPanel Orientation=Horizontal> <TextBox Name=txbInterval Text=5/> <Image Name=imgStart Source=Images/start.png/> <Image

  • 0

I have wpf user control

<StackPanel Orientation="Horizontal">
            <TextBox Name="txbInterval" Text="5"/>
            <Image Name="imgStart" Source="Images/start.png"/>
            <Image Name="imgStop" Source="Images/stop.png"/>
</StackPanel>

I use this control in my application many times. This control can start/stop executing tasks in my own scheduler. When imgStart is clicked, it should create new instance of some task with txbInterval.Text argument. I have this in my MainWindow.xaml

<wp:TaskManager x:Name="tmToolsArMail"/>
<wp:TaskManager x:Name="tmToolsArSail"/>

and I need in Mainwindow.xaml.cs something like this

tmToolsArMail_imgStart_mouseUp(...)
... new MyTask(tmToolsArMail.txbInterval.Text) ...

tmToolsArSail_imgStart_mouseUp(...)
... new MyAnotherTask(tmToolsArSail.txbInterval.Text) ...

How?

  • 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-30T12:57:52+00:00Added an answer on May 30, 2026 at 12:57 pm

    What I would do would be to put RoutedEvents in the user control like this:

        public MyUserControl()
        {
            InitializeComponent();
    
            imgStart.MouseUp += imgStart_MouseUp;
            imgStop.MouseUp += imgStop_MouseUp;
        }
    
        // Create custom routed events by first registering a RoutedEventID
        // These events use the bubbling routing strategy
        public static readonly RoutedEvent StartEvent = EventManager.RegisterRoutedEvent(
            "Start", RoutingStrategy.Bubble, typeof(RoutedEventHandler), typeof(MyUserControl));
    
        public static readonly RoutedEvent StopEvent = EventManager.RegisterRoutedEvent(
            "Stop", RoutingStrategy.Bubble, typeof(RoutedEventHandler), typeof(MyUserControl));
    
        // Provide CLR accessors for the events
        public event RoutedEventHandler Start
        {
            add { AddHandler(StartEvent, value); }
            remove { RemoveHandler(StartEvent, value); }
        }
    
        // Provide CLR accessors for the events
        public event RoutedEventHandler Stop
        {
            add { AddHandler(StopEvent, value); }
            remove { RemoveHandler(StopEvent, value); }
        }
    
        // This method raises the Start event
        void RaiseStartEvent()
        {
            RoutedEventArgs newEventArgs = new RoutedEventArgs(MyUserControl.StartEvent);
            RaiseEvent(newEventArgs);
        }
    
        // This method raises the Stop event
        void RaiseStopEvent()
        {
            RoutedEventArgs newEventArgs = new RoutedEventArgs(MyUserControl.StopEvent);
            RaiseEvent(newEventArgs);
        }
    
        private void imgStart_MouseUp(object sender, MouseButtonEventArgs e)
        {
            RaiseStartEvent();
        }
    
        private void imgStop_MouseUp(object sender, MouseButtonEventArgs e)
        {
            RaiseStopEvent();
        }
    

    Then any code which calls into this UserControl can subscribe to those Start and Stop events and do the handling you require.

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

Sidebar

Related Questions

I have a WPF user control containing a Text box and a button. I
I have a WPF user control where I have multiple text boxes and and
I have a WPF user control with a number of textboxes, this is hosted
I have a wpf user control which exposes an IEnumerable ItemsSource DependencyProperty. I bind
I have a WPF User control that binds to a DataTable and generates CheckBox
I have a newbie WPF question. Imagine my user control has a namespace declaration
I have the following problem in wpf: I have defined a user control (in
I have this custom wpf user control: ShowCustomer.xaml: <UserControl x:Class=TestControlUpdate2343.Controls.ShowCustomer xmlns=http://schemas.microsoft.com/winfx/2006/xaml/presentation xmlns:x=http://schemas.microsoft.com/winfx/2006/xaml> <Grid> <TextBlock
I have created a custom TaskButton control that takes an image and text. The
I have a WPF user control that I want to print. I am able

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.