I got a very strange problem. I want to open a contextmenu on left click on a button... Here is my solution but it fires an System.ComponentModel.Win32Exception.
public class ButtonKontext : System.Windows.Controls.Button
{
public ButtonKontext()
{
this.Click += new System.Windows.RoutedEventHandler(this.Button_Click_1);
}
public void Button_Click_1(object sender, RoutedEventArgs e)
{
if (this.ContextMenu != null)
{
//ContextMenu contextMenu = this.ContextMenu;
//this.ContextMenu.PlacementTarget = this;
this.ContextMenu.IsOpen = true; // System.ComponentModel.Win32Exception here
}
}
}
System.ComponentModel.Win32Exception: "Untergeordnetes Fenster kann nicht auf der obersten Ebene erstellt werden" --> edit: Child window can not be created at the top level – Thx Jimenemex for correct translation.
The thing is, if i right click the button the contextmenu shows up normal. So what is the problem here? Any idea?