Hi,
I am trying to create a sample window with a custom toolbar and button controls in the toolbar, I am able to create a window but couldn't find any sample on how to add NSToobar to the window and NSToolbarItem to NSToolbar via code. How can this be done programmatically?
Thanks.
You can find some examples online if you search for nstoolbar programmatically Cocoa
. Those will all be in Objective-C, but as noted in the FAQ:
There are a number of samples in general (https://developer.xamarin.com/samples/mac/all/) but they are far from complete in covering all APIs. Often you'll need to convert objective-c stack overflow / tutorials / apple documentation to C# and this documentation will help:
https://developer.xamarin.com/guides/mac/application_fundamentals/patterns/
https://developer.xamarin.com/guides/mac/application_fundamentals/mac-apis/
Answers
Xamarin.Mac integrates directly with Xcode, it's possible to use Xcode's Interface Builder to create and maintain toolbar items. Check https://docs.microsoft.com/en-us/xamarin/mac/user-interface/toolbar#setting-a-custom-main-window-controller .
@LucasZhang thanks for the reply, this link helps but I am trying to add NSToolbar via code in c#. How can this be done programmatically?
You can find some examples online if you search for
nstoolbar programmatically Cocoa
. Those will all be in Objective-C, but as noted in the FAQ: