As i see in janus there is UIButton that has an arrow on it , so when you click on it , it can open a menu.
I dont know how to add items so when you click on that Arrow, that is on UIButton, the menu will be open.
Can someone explain me please?
You will need to set the ButtonStyle to DropDown. It will now accept a new property called DropDownContextMenu, which will allow you to attach a context menu to the UIButton dropdown. Here's a quick example setting it in code:
public Form1()
{
InitializeComponent();
uiButton1.ButtonStyle = Janus.Windows.EditControls.ButtonStyle.DropDown;
var menu = new Janus.Windows.UI.CommandBars.UIContextMenu();
menu.Commands.Add(new Janus.Windows.UI.CommandBars.UICommand("1", "Item1"));
menu.Commands.Add(new Janus.Windows.UI.CommandBars.UICommand("2", "Item2"));
uiButton1.DropDownContextMenu = menu;
}
Related
I have a context menu for notifyIcon, in which for one of the menu items I want to provide a submenu with three options that can be checked/unchecked. But I want this submenu to appear only when the user hovers/clicks over the arrow in the parent menu item. I.e., the user should be able to select the parent menu item without having to open its submenu, and the default values of the options in the submenu will be used in the parent menu's handler. Is this possible?
I am using Winforms with .Net framework 4.8.1 -
MenuItem[] submenu = new MenuItem[]
{
new MenuItem("Italic",OpenItalic){ DefaultItem = true},
new MenuItem("Bold",OpenBold),
new MenuItem("Underline", OpenUnderline)
};
MenuItem[] menuItems = {
new MenuItem("Show text", submenu)
};
icon = new NotifyIcon()
{
ContextMenu = new ContextMenu(menuItems),
Icon = new System.Drawing.Icon("instance.ico"),
Visible = true,
Text = "test"
};
Here user has to select from the submenu items bold/italic/underline each time to open a form. Can we keep 'italic' as default option and allow the user to open the form by clicking 'Show text' option itself, and only open the submenu when there is a need to change the option?
I need to show a menu on an NSTableView when user right clicks anywhere on the table row. Just like when we right click anywhere in the browser and menu shows up.
NSTableView has Menu property that can be assigned to your NSMenu.
Of course all this can be done in Xcode's IB, but if you are doing this programmatically you need to construct a NSMenu, add the NSMenuItem(s) required and assign it to the NSTableView.
var menu = new NSMenu("A context menu")
{
Delegate = this
};
menu.AddItem(new NSMenuItem { Title = "StackOverflow" Action = SomeMenuAction });
aTableView.Menu = menu;
I started out C# very recently and sorry if this question sounds dumb.
How do I add a Listbox in a Form that pops out from a Button click?
Note: The Form isn't the one that's added from the Solution Explorer whereby I can just drag a Listbox from the Toolbox to my Form.
So what I want is to create a ListBox in my file drawer1Form where I can add additional items. Thanks for the help in advance!:)
private void drawer1button_Click(object sender, EventArgs e) // Drawer 1 Button
{
drawer1Form df1 = new drawer1Form();
df1.StartPosition = FormStartPosition.CenterScreen;
df1.Show();
}
public partial class drawer1Form : Form // Creates drawer1Form
{
public drawer1Form()
{
Text = "Drawer 1 ";
}
}
Pretty much the same way as you'd do with any other object.
In the class of your form add a
private ListBox myAwesomeListBox;
Then in the button event handler add something like this:
myAwesomeListBox = new ListBox();
myAwesomeListBox.SuspendLayout();
// set all the properties that you want
myAwesomeListBox.Name = "myAwesomeListBox";
myAwesomeListBox.Location = new Point(...); // place it somewhere
myAwesomeListBox.Size = new Size(...); // give it a size
// etc...
df1.Controls.Add(myAwesomeListBox);
myAwesomeListBox.ResumeLayout();
This should be it.
I highly advise you to do it through the designer first though, and then take a look at the generated code in the form's .Designer.cs file, you'll have a very good understanding after reading through that.
I'm unable to get the keyboard shortcuts working on context menu items belonging to specific controls and I was wondering if anyone could help me.
Use case: I'm trying to write an attached behavior that can be applied to various elements in order to provide undo/redo context menu functionalists to those controls. The context menu part is working but the key bindings don't seem to work.
What I've tried so far:
Attempt 1:
var menu = new ContextMenu();
var undoCommand = new DelegateCommand(Undo);
var undoMenuItem = new MenuItem
{
Header = "Undo",
Command = undoCommand,
InputGestureText = "Ctrl+Z",
};
menu.Items.Add(undoMenuItem);
AssociatedObject.ContextMenu = menu; // AssociatedObject is a textbox as an example
Attempt 2:
var menu = new ContextMenu();
var undoCommand = new DelegateCommand(Undo);
var undoMenuItem = new MenuItem
{
Header = "Undo",
Command = undoCommand,
};
undoMenuItem.InputBindings.Add(new InputBinding(undoCommand,
new KeyGesture(Key.Z, ModifierKeys.Control)))
menu.Items.Add(undoMenuItem);
AssociatedObject.ContextMenu = menu; // AssociatedObject is a textbox as an example
Neither of these seem to be working. The context menu is selectible from the UI (right click on a text box for instance and select "Undo") but the keyboard shortcut is not fired.
Is there a way to do this in an attached behavior? I would like to avoid having access to the underlying Window element inside my attached behavior if possible and would like the keys to work within their respective bounds (for instance, only if the text box is focused should Ctrl+Z cause an Undo on that text box).
Many thanks
I have used Xamrin.forms.labs to create Imagebutton in shared code. Number of imagebuttons varies according to the number of elements in the list. My questions are
How can I identify which button is clicked? (I need the text of the Imagebutton for identification)
I have to change the image to Source_on.png on the first click of the image button and change back to Source.png on second click. (Just like select and unselect)
How can I acheive it??
The code I have used to create ImageButtons is given below.
StackLayout Holder = new StackLayout {
HorizontalOptions=LayoutOptions.FillAndExpand,
VerticalOptions=LayoutOptions.Center,
Orientation=StackOrientation.Horizontal,
Spacing=2,
};
foreach (var options in list)
{
var Icon = new ImageButton () {
Source=Source.png,
BackgroundColor=Xamarin.Forms.Color.Transparent,
HorizontalOptions=LayoutOptions.CenterAndExpand,
VerticalOptions=LayoutOptions.CenterAndExpand,
Orientation=Xamarin.Forms.Labs.Enums.ImageOrientation.ImageOnTop,
Text=labeltxt,
};
Icon.Clicked += OnSelected;
Holder.Children.Add (Icon );
}
}
Providing a helpful link or sample code will be really helpful..
Thanks in Advance..
It would help a lot if you share the code of your ImageButton.
That being said... if your ImageButton has a Command property it would also have a CommandParameter property. If it doesn't have that - make them.
You'd set the CommandParameter property with some ID and then bind the Command to the same code, such as
ImageButton icon = null;
icon = new ImageButton{
...
Command= new Command((tag)=>{
icon.Source = ImageSource.FromFile("...");// see other .FromXYZ methods too
},
CommandParameter="<your tag here>",
}
BUT... before you do all of that check out the Xamarin.Forms.Labs, there's an ImageButton there already and you can add that project from NuGet by searching for "Xamarin Forms Labs" in the package manager