UIControllerInvoke(Action) Method
Invokes a
action that will be handled by an
Handler.
Namespace: Firefly.BoxAssembly: Firefly.Box (in Firefly.Box.dll) Version: debug-master-v:33791
public void Invoke(
Action action
)
Public Sub Invoke (
action As Action
)
member Invoke :
action : Action -> unit
Parameters
- action Action
- The Action to be invoked
When the
Handler method is called, the framework will iterate the
Handlers property collection until it will find an
Handler that matches the
action.
If no matching
Handler was found, or if the
Handled property was set to true, the framework will iterate the calling task's
Handlers property collection and so on.
The deference between Raise and Invoke, is that Raise will queue the
action, and process it the next time the framework is idle, while Invoke will process it immediately
When invoking a {0} (for example {1}) or a Key Combination, only the relevant Handlers will execute, but the command it self will not. In order to run the command itself use .
Raising and handling of events in a UI
This example is based on test data. The code for the entities included in this test data can be found in the documentation of
EntityThis example uses automatic tools to generate parts of the user interface. Those tools can be found in the example of the documentation of
Formusing System.Drawing;
using System.Windows.Forms;
using Firefly.Box;
namespace TestFirefly.Box.Documentation
{
public class DemoRaiseDelete
{
public void RaiseDelete()
{
var jobs = new Pubs.Jobs();
jobs.InitializeWithTestData();
var uic = new UIController
{
From = jobs,
View = UITools.GenerateFormWithGridFor("Display Jobs",
"Click the Delete button to delete the current row",
jobs.Id,
jobs.Description,
jobs.MinLevel,
jobs.MaxLevel)
};
var deleteButton = new Button
{
Text = "Delete",
};
UITools.AddControlsToForm(uic.View, deleteButton);
//raise the delete command by the button
deleteButton.Click += (a, b) => uic.Raise(Command.DeleteRow);
uic.Run();
}
public void HandlingDelete()
{
var jobs = new Pubs.Jobs();
jobs.InitializeWithTestData();
var uic = new UIController
{
From = jobs,
View = UITools.GenerateFormWithGridFor("Display Jobs",
"Click the delete button, and see how the custom handler for the delete command"+
" takes affect",
jobs.Id,
jobs.Description,
jobs.MinLevel,
jobs.MaxLevel)
};
var deleteButton = new Button
{
Text = "Delete",
};
UITools.AddControlsToForm(uic.View, deleteButton);
//raise the delete command by the button
deleteButton.Click += (a, b) => uic.Raise(Command.DeleteRow);
uic.Handlers.Add(Command.DeleteRow).Invokes += e =>
{
if (MessageBox.Show(
"Are you sure you want to delete this row",
"Confirm Delete",
MessageBoxButtons.YesNo) == DialogResult.Yes)
e.Handled = false;
};
uic.Run();
}
}
}