Hi I create a contextmenu dynamicly using this code
protected MenuItem itemAdd, itemDelete, itemSelectBranch, itemDeleteClasp;
protected MenuItem itemCut, itemCopy, itemPaste, itemAddParent, itemPasteWithChildren;
protected MenuItem itemAddTask, itemAddExtTask, itemAddMileStone;
menu = new ContextMenu();
itemAdd = new MenuItem
{
HorizontalAlignment = HorizontalAlignment.Left,
HorizontalContentAlignment = System.Windows.HorizontalAlignment.Stretch,
Header = "Add"
};
itemDelete = new MenuItem
{
HorizontalAlignment = HorizontalAlignment.Left,
HorizontalContentAlignment = System.Windows.HorizontalAlignment.Stretch,
Header = "Delete"
};
itemSelectBranch = new MenuItem
{
HorizontalAlignment = HorizontalAlignment.Left,
HorizontalContentAlignment = System.Windows.HorizontalAlignment.Stretch,
Header = "Select"
};
itemAddTask = new MenuItem
{
HorizontalAlignment = HorizontalAlignment.Left,
HorizontalContentAlignment = System.Windows.HorizontalAlignment.Stretch,
Header = "Task",
};
itemAddParent = new MenuItem
{
HorizontalAlignment = HorizontalAlignment.Left,
HorizontalContentAlignment = System.Windows.HorizontalAlignment.Stretch,
Header = "Parent"
};
itemAddMileStone = new MenuItem
{
HorizontalAlignment = HorizontalAlignment.Left,
HorizontalContentAlignment = System.Windows.HorizontalAlignment.Stretch,
Header = "Do sth",
};
itemAddExtTask = new MenuItem
{
HorizontalAlignment = HorizontalAlignment.Left,
HorizontalContentAlignment = System.Windows.HorizontalAlignment.Stretch,
Header = "Do sth"
};
itemDelete.HorizontalAlignment = HorizontalAlignment.Left;
itemDelete.Click += itemDelete_Click;
itemDeleteClasp = new MenuItem
{
HorizontalContentAlignment = System.Windows.HorizontalAlignment.Stretch,
HorizontalAlignment = HorizontalAlignment.Left,
Header = "Do sthm"
};
itemDeleteClasp.Click += itemDeleteClasp_Click;
itemCopy = new MenuItem {Header = Do sth",HorizontalAlignment = System.Windows.HorizontalAlignment.Left};
itemCopy.Click += itemCopy_Click;
itemCut = new MenuItem
{
HorizontalAlignment = HorizontalAlignment.Left,
Header = "Cut"
};
itemPaste = new MenuItem
{
HorizontalAlignment = HorizontalAlignment.Left,
Header = "Paste"
};
itemAddParent = new MenuItem
{
HorizontalAlignment = HorizontalAlignment.Left,
Header = "Do sth"
};
itemPasteWithChildren = new MenuItem
{
HorizontalAlignment = HorizontalAlignment.Left,
Header = "some long text"
};
itemPasteWithChildren.Click += itemPasteWithChildren_Click;
itemAddParent.Click += itemAddParent_Click;
itemPaste.Click += itemPaste_Click;
itemCut.Click += itemCut_Click;
itemAddTask.Click += itemAddTask_Click;
itemAddExtTask.Click += itemAddExtTask_Click;
itemAddMileStone.Click += itemAddMileStone_Click;
itemAddParent.Click += itemAddParent_Click;
itemSelectBranch.Click += itemSelectBranch_Click;
itemAdd.Items.Add(itemAddTask);
itemAdd.Items.Add(itemAddExtTask);
itemAdd.Items.Add(itemAddMileStone);
itemAdd.Items.Add(itemAddParent);
menu.Items.Add(itemAdd);
menu.Items.Add(itemDelete);
menu.Items.Add(itemDeleteClasp);
menu.Items.Add(itemSelectBranch);
menu.Items.Add(itemCopy);
menu.Items.Add(itemCut);
menu.Items.Add(itemPaste);
This menu is attached to textbox.contextmenu property. However menu looks strange. Every text in menu items is centered. It looks quite ugly and frankly speaking I don't know why this looks that way. Could somebody explain me how I can make it align to left ?