S
Simon Woods
Hi
I am trying to get my head around delegates (and MVC)...
I have a simple app ... a view form, a popup form and a controller class
When a particular key is pressed in the view, I want to popup the popup.
Then, when a particular key is pressed in the popup I want to return the
selected value in the popup form to the view. I am using the controller
class as an intermediary between the two.
Here's a clip from the controller:
//member
SetValue _setValue;
GetValue IController.GetPopupValue
{
get
{
return value =>
{
_setValue.Invoke(value);
};
}
}
SetValue IController.SetPopupValue
{
get
{
return _setValue;
}
}
....
public delegate void GetValue(string value);
public delegate void SetValue(string value);
As you can see,
1) I have a lambda, GetPopupValue, which receives the value from the
popup (that's working fine) which invokes the delegate
2) I have a delegate called SetValue defined in the controller. It gets
passed into the view on it's construction.
public TextBox(SetValue popupValue)
{
popupValue= delegate(string value)
{
_txtMain.AppendText(value);
};
}
What I was effectively wanting was to be able to assign the action to be
taken when the delegate is passed into the view, so that when the
delegate is invoked in the controller, the action occurs in the view.
However, I'm getting a null reference exception when I try and invoke it
in the view , as I sort of expected, since the action to be taken
against that definition is defined in the view.
Can someone explain, how I should be wiring this up so that, effectively
I get remote execution of the delegate, declared and invoked in the
controller yet defined and executed in the view?
Many thx
Simon
I am trying to get my head around delegates (and MVC)...
I have a simple app ... a view form, a popup form and a controller class
When a particular key is pressed in the view, I want to popup the popup.
Then, when a particular key is pressed in the popup I want to return the
selected value in the popup form to the view. I am using the controller
class as an intermediary between the two.
Here's a clip from the controller:
//member
SetValue _setValue;
GetValue IController.GetPopupValue
{
get
{
return value =>
{
_setValue.Invoke(value);
};
}
}
SetValue IController.SetPopupValue
{
get
{
return _setValue;
}
}
....
public delegate void GetValue(string value);
public delegate void SetValue(string value);
As you can see,
1) I have a lambda, GetPopupValue, which receives the value from the
popup (that's working fine) which invokes the delegate
2) I have a delegate called SetValue defined in the controller. It gets
passed into the view on it's construction.
public TextBox(SetValue popupValue)
{
popupValue= delegate(string value)
{
_txtMain.AppendText(value);
};
}
What I was effectively wanting was to be able to assign the action to be
taken when the delegate is passed into the view, so that when the
delegate is invoked in the controller, the action occurs in the view.
However, I'm getting a null reference exception when I try and invoke it
in the view , as I sort of expected, since the action to be taken
against that definition is defined in the view.
Can someone explain, how I should be wiring this up so that, effectively
I get remote execution of the delegate, declared and invoked in the
controller yet defined and executed in the view?
Many thx
Simon