Answer the question
In order to leave comments, you need to log in
Creating an attached event?
There is a line
sp.AddHandler(Button.Click , new RoutedEventHandler(DoSomething));
<StackPanel Name="sp" Width="{Binding ElementName=MainGrid, Path=ActualWidth}" Height="{Binding ElementName=MainGrid, Path=ActualHeight}" >
private void DoSomething(object sender, RoutedEventArgs e)
{
if(e.OriginalSource==BTN)
{
BTN.Content = ContentControl.ActualHeightProperty;
}
}
sp.AddHandler(Button.Click , new RoutedEventHandler(DoSomething));
- an error occurs - swears at Button.Click
-Error CS0120 The non-static field, method, or property 'ButtonBase.Click' requires an object reference.
Button.Click
- this is an event - except to subscribe to it on a delegate sp.AddHandler(Button.Click+= new RoutedEventHandler(), new RoutedEventHandler(DoSomething));
Button.Click+= new RoutedEventHandler()
RoutedEventHandler()
sp.AddHandler(Button.Click , new RoutedEventHandler(DoSomething));
) - that is, the Click event is simply called on the Button object class and passed as the first parameter to AddHandler) Error CS0120 The non-static field, method, or property 'ButtonBase.Click' requires an object reference.
Button.Click
sp.AddHandler(Button.Click += new RoutedEventHandler(retBTN), new RoutedEventHandler(DoSomething));
private Button retBTN(object sender, RoutedEventArgs e)
{
return (Button)sender ;
}
- but then the compiler swears that retBTN - has the wrong return type - apparently does not match the signature of the RoutedEventHandler delegate class. And I don't know what to do next.
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question