Xamarin - XAML - top bar app menu - xaml

I am working on Xamarin Mac app with XAML, but I am not able to add app menu to top bar. I think, that it is generated with xCode in Main.storyboard, but I am not using xCode, because of using XAML.

Found solution. I post it here for someone who can use it.
For adding menu item for quit app (in AppDelegate.cs):
// top bar app menu
NSMenu menubar = new NSMenu();
NSMenuItem appMenuItem = new NSMenuItem();
menubar.AddItem(appMenuItem);
NSMenu appMenu = new NSMenu();
// add quit menu item
string quitTitle = String.Format("Quit {0}", "appname");
var quitMenuItem = new NSMenuItem(quitTitle, "q", delegate {
NSApplication.SharedApplication.Terminate(menubar);
});
appMenu.AddItem(quitMenuItem);
// finally add menu
NSApplication.SharedApplication.MainMenu = menubar;

Related

MenuItem disabled after turning off the view

I set up a project with two view controllers connected to two xibs (MainMenu.xib and MasterVC.xib)
In my MasterVC I programatically add NSMenuItems with actions (located in MasterVC) to a menu, that is located in MainMenu.xib (and is connected to AppDelegate).
let menuItem = NSMenuItem()
menuItem.title = object.name!
menuItem.keyEquivalent = object.shortcut!
menuItem.representedObject = object
menuItem.action = "testSelector:"
appDel.menu.insertItem(menuItem, atIndex: 0)
func testSelector(sender: NSMenuItem) {
let object = (sender.representedObject as! MyNewObject)
print("Name of set:", object.name)
}
My added menu items work (are enabled) as long as I have window from MasterVC opened. As soon as I close it I can't click those menu items (they are disabled).
Is there a way to keep them enabled all the time?
You need to do two steps in your storyboard or XIB file (whichever contains the main menu):
1)
Use the Attribute Inspector after selecting the menu and then turn off "Auto Enable Items" checkbox:
]
2)
And for each menu item you want to have enabled, select that menu item and use the Attributes Inspector to make sure this checkbox is set to on:
]

appcelerator hide actionBar from tabgroup

I want to hide ActionBar from tabGroup in appcelerator titanium android.
When we create new project in appcelerator it by defaults has a tabbar and an actionbar on it. I want to remove that actionBar and only want to have tabs in my tab group I tried many codes one of them is as below
tabGroup.addEventListener("open", function() {
var actionBar = tabGroup.getActivity().actionBar;
if (actionBar) {
actionBar.hide();
}
});
But this code sample also hides the tabs of my tabgroup.
Please help me.
Thanks in advance.
Unfortunately that is not possible. Titanium mobile implements TabGroup and Tabs using ActionBar.Tab functionality Source code of Titanium TabGroup
So if you hide the ActionBar, you will hide the Tabs as well :)
I had the same problem, you can set the tabGroup Title to empty, the Title bar will disappear automatically :
var tabGroup = Titanium.UI.createTabGroup({
title:'',
});

Adding a Back button to a iOS app in Titanium Appcelerator without TabGroup or NavBar

I'm developing with Titanium Appcelerator for iOS. I would like to manage manually a 'back' button using the properties of window, that can set a left and right buttons.
I'm trying with this code:
var win = Titanium.UI.currentWindow;
win.backgroundColor = '#FFF';
var b = Titanium.UI.createButton({title:'Back'});
win.setLeftNavButton(b);
b.addEventListener('click', function()
{
win.close();
});
But no button is showed.
Swanand is right but i want to add some more thing that if you use modal property of window to open then also you can use setLeftNavButton method to set button in navigation bar but if you do not want to use tab group or navigation group or even modal property then you need to add that button in window with left,top,width and height property.
You can use below example....
var win = Titanium.UI.currentWindow;
win.backgroundColor = '#FFF';
var b = Titanium.UI.createButton({
title:'Back',
width : Ti.UI.SIZE,
height : Ti.UI.SIZE,
top : 10,
left : 10
});
win.add(b);

ios 7 auto resize UINavigationController when In-Call status bar is toggle Monotouch

I'm having a problem when the in-call status bar it shows, I have tried.
navigationController = new UINavigationController ();
navigationController.NavigationBarHidden = true;
navigationController.View.AutosizesSubviews = true;
navigationController.View.AutoresizingMask = UIViewAutoresizing.FlexibleHeight|UIViewAutoresizing.FlexibleMargins|
UIViewAutoresizing.FlexibleTopMargin|UIViewAutoresizing.FlexibleBottomMargin;
navigationController.View.SizeToFit ();
window.RootViewController = navigationController;
window.RootViewController.View.AutosizesSubviews = true;
navigationController.View.AutoresizingMask = UIViewAutoresizing.FlexibleHeight|UIViewAutoresizing.FlexibleMargins|
UIViewAutoresizing.FlexibleTopMargin|UIViewAutoresizing.FlexibleBottomMargin;
but is still pushing bottom all views, hiding all buttons or controls at the bottom of the view, I also tried the same code in the Root View controller and doesn't work.
I'm using flexible UI for all controls this way:
btnContacts = IOTM.GUI.CreateButton ("MainMenu/btncontacts.png", 0f,Frame.Height - (Frame.Height * 0.225f), Frame.Width, (Frame.Height * 0.075f));
and I'm also hiding Navigation Bar
Can someone help me?
There is another way to auto resize view or detect changes in status bar to reload my views?

WinJS AppBar button flash on Hide

My application has a WinJS AppBar control at the bottom of the screen. I use .showOnlyCommands(buttonsToShowArray) to show and hide buttons on ListView itemSelectionChanged event.
The problem I have right now is that when every I call .showOnlyCommands, the buttons to be hidden (or you may say "replaced") are going to flash on the top of the screen.
I tried to use the Microsoft sample app, this doesn't happen. I tried to use .showCommands + .hideCommands method, it is the same behavior. Note that this didn't happen before the Release Preview version of Win8.
I have no idea what is going on. Any idea?
EDIT:
I did further investigation, the problem happens on hideCommands. Say I have 3 buttons displayed on the appbar. I call hideCommands to hide all 3 buttons. The icon of the 3 buttons would disappear on the appbar, then pile up at the top-left corner of the screen and then disappear. (i.e. there would be a flash of 3 piled up buttons at the corner of the screen).
You may be invoking showOnlyCommands when the AppBar is in the process of 'showing'. I've found that when calling these methods in the beforeshow or aftershow handler that this happens. This quote from Animating your UI sheds light on why:
Use fade in and fade out animations to show or hide transient UI or controls. One example is in an app bar in which new controls can appear due to user interaction.
The sample app shows/hides the buttons before the appbar is shown. You may be calling show on the app bar before calling showOnlyCommands.
A temporary hack for this problem is:
Set the button be invisible before calling showOnlyCommands or HideCommands.
Here is the code that I use for now:
/*
* #param {WinJS.UI.AppBar} appbar winControl
* #param {Array} array of appbar buttons to be shown
*/
function showOnlyCommands(appbarControl, buttonsToShow) {
var toShow = {};
for (var i = 0; i < buttonsToShow.length; i++) {
toShow[buttonsToShow[i].id] = true;
}
for (var i = 0; i < visibleButtonsList.length; i++) {
var id = visibleButtonsList[i].id;
if (!toShow[id]) {
// set the display property of the buttons to be hidden to "none"
var button = document.getElementById(id);
if (button) {
button.style.display = 'none';
}
}
}
// update the visible buttons list
visibleButtonsList = buttonsToShow;
// Note that we don't need to set the "display" property back for the buttons,
// because WinJS.UI.AppBar.showOnlyCommands would set it back internally
appbarControl.showOnlyCommands(buttonsToShow);
}