Click here to Skip to main content
15,912,897 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Hello i have this: but not works

C#
namespace WpfDialControl
{

    public partial class DialControlMod_0 : UserControl
    {
        public delegate void ValueChangedEventHandler(object Sender);
        public event ValueChangedEventHandler ValueChanged;
....
....

        protected virtual void OnValueChanged(object sender)
        {
            if (ValueChanged != null)
                ValueChanged(sender);
        }


....
....


   public partial class MainWindow : Window
    {
        public MainWindow()
        {
            InitializeComponent();
            MyKnob.ValueChanged += new DialControlMod_0.ValueChangedEventHandler(MyKnob_ValueChanged);
        }

        private void MyKnob_ValueChanged(object Sender)
        {
            MessageBox.Show("hola");

//Test not works
        }
    }
Posted
Comments
Sergey Alexandrovich Kryukov 7-Feb-13 20:30pm    
"Not works" is not informative.
—SA
Victor Rene 8-Feb-13 20:29pm    
That's true. Some things are missing:
- The property (which fires the event on update through the setter)
- EventArgs class
- Probably the syntax of the event is wrong. Either it's an anonymous function, or it's a regular function. Mixing things will not work.

There is nothing which can "work" here. You don't show any code which calls your method OnValueChanged, that's the problem; you just formally defined this method, now what?

You simply don't understand how events work and what they are used for. I could explain, but better just read about it: http://msdn.microsoft.com/en-us/library/awbftdfh.aspx[^].

Helping with your particular problem is useless before your 1) learn the above material; in might require to learn the prerequisites required for understanding of this topic; 2) if you still don't know how to define and use events by that time, describe required functionality. In particular, if the event is called "ValueChanged", at least you should have the property Value; and the testing code should try to modify the value of this property ("Change" it, right?), and that should invoke the event. The problem is not the names of properties or events; I'm just trying to give you a hint.

—SA
 
Share this answer
 
What a sad answer from SA.
He would have be better off not even wasting his time posting an answer
 
Share this answer
 
Comments
CHill60 16-Mar-15 4:24am    
As would you. This is not a solution to the problem, which itself is over 2 years old. Use the appropriate "Have a Question or Comment?" links to comment on posts

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900