void CreateMenuToolBar()
{
var about = new Commands.About();
var quit = new Commands.Quit();
if (Platform.Supports<MenuBar>())
{
var fileCommand = new Command { MenuText = "File Command", Shortcut = Application.Instance.CommonModifier | Keys.F };
fileCommand.Executed += (sender, e) => Log.Write(sender, "Executed");
var editCommand = new Command { MenuText = "Edit Command", Shortcut = Keys.Shift | Keys.E };
editCommand.Executed += (sender, e) => Log.Write(sender, "Executed");
var viewCommand = new Command { MenuText = "View Command", Shortcut = Keys.Control | Keys.V };
viewCommand.Executed += (sender, e) => Log.Write(sender, "Executed");
var windowCommand = new Command { MenuText = "Window Command" };
windowCommand.Executed += (sender, e) => Log.Write(sender, "Executed");
var file = new ButtonMenuItem { Text = "&File", Items = { fileCommand } };
var edit = new ButtonMenuItem { Text = "&Edit", Items = { editCommand } };
var view = new ButtonMenuItem { Text = "&View", Items = { viewCommand } };
var window = new ButtonMenuItem { Text = "&Window", Order = 1000, Items = { windowCommand } };
if (Platform.Supports<CheckMenuItem>())
{
edit.Items.AddSeparator();
var checkMenuItem1 = new CheckMenuItem { Text = "Check Menu Item", Shortcut = Keys.Shift | Keys.K };
checkMenuItem1.Click += (sender, e) => Log.Write(checkMenuItem1, "Click, {0}, Checked: {1}", checkMenuItem1.Text, checkMenuItem1.Checked);
checkMenuItem1.CheckedChanged += (sender, e) => Log.Write(checkMenuItem1, "CheckedChanged, {0}: {1}", checkMenuItem1.Text, checkMenuItem1.Checked);
edit.Items.Add(checkMenuItem1);
var checkMenuItem2 = new CheckMenuItem { Text = "Initially Checked Menu Item", Checked = true };
checkMenuItem2.Click += (sender, e) => Log.Write(checkMenuItem2, "Click, {0}, Checked: {1}", checkMenuItem2.Text, checkMenuItem2.Checked);
checkMenuItem2.CheckedChanged += (sender, e) => Log.Write(checkMenuItem2, "CheckedChanged, {0}: {1}", checkMenuItem2.Text, checkMenuItem2.Checked);
edit.Items.Add(checkMenuItem2);
}
if (Platform.Supports<RadioMenuItem>())
{
edit.Items.AddSeparator();
RadioMenuItem controller = null;
for (int i = 0; i < 5; i++)
{
var radio = new RadioMenuItem(controller) { Text = "Radio Menu Item " + (i + 1) };
radio.Click += (sender, e) => Log.Write(radio, "Click, {0}, Checked: {1}", radio.Text, radio.Checked);
radio.CheckedChanged += (sender, e) => Log.Write(radio, "CheckedChanged, {0}: {1}", radio.Text, radio.Checked);
edit.Items.Add(radio);
if (controller == null)
{
radio.Checked = true; // check the first item initially
controller = radio;
}
}
}
Menu = new MenuBar
{
Items =
{
// custom top-level menu items
file, edit, view, window
},
ApplicationItems =
{
// custom menu items for the application menu (Application on OS X, File on others)
new Command { MenuText = "Application command" },
new ButtonMenuItem { Text = "Application menu item" }
},
HelpItems =
{
new Command { MenuText = "Help Command" }
},
QuitItem = quit,
AboutItem = about
};
}
if (Platform.Supports<ToolBar>())
{
// create and set the toolbar
ToolBar = new ToolBar();
ToolBar.Items.Add(about);
if (Platform.Supports<CheckToolItem>())
{
ToolBar.Items.Add(new SeparatorToolItem { Type = SeparatorToolItemType.Divider });
ToolBar.Items.Add(new CheckToolItem { Text = "Check", Image = TestIcons.TestImage });
}
ToolBar.Items.Add(new SeparatorToolItem { Type = SeparatorToolItemType.Space });
ToolBar.Items.Add(new ButtonToolItem { Text = "Click Me", Image = TestIcons.Logo });
if (Platform.Supports<RadioToolItem>())
{
ToolBar.Items.Add(new SeparatorToolItem { Type = SeparatorToolItemType.FlexibleSpace });
ToolBar.Items.Add(new RadioToolItem { Text = "Radio1", Image = TestIcons.Logo, Checked = true });
ToolBar.Items.Add(new RadioToolItem { Text = "Radio2", Image = TestIcons.TestImage });
ToolBar.Items.Add(new RadioToolItem { Text = "Radio3 (Disabled)", Image = TestIcons.TestImage, Enabled = false });
}
}
}