Announcement

Collapse
No announcement yet.

Problem mit Windows Forms in WPF

Collapse
X
  • Filter
  • Time
  • Show
Clear All
new posts

  • Problem mit Windows Forms in WPF

    Hallo,
    ich habe eine kleine Anwendung geschrieben, die ein Liste von Computer beinhaltet, die in regelmäßigen Abständen angepingt werden um zu prüfen ob sie noch online sind. Da es das NotifyIcon in WPF noch nicht gibt habe ich halt die Windows Forms.dll angebunden und mir das daraus genommen, damit mein Programm eben im Systemtray angezeigt wird. Das Programm läuft auch soweit ganz gut, Solange ich es aus der IDE im Debug starte. Starte ich die komplimierte Exe direkt kommt folgendes:
    Code:
    ************** Ausnahmetext **************
    System.ArgumentException: ContextMenu kann nicht auf einem unsichtbarem Steuerelement angezeigt werden.
    Parametername: control
       bei System.Windows.Forms.ContextMenu.Show(Control control, Point pos, Int32 flags)
       bei System.Windows.Forms.ContextMenu.Show(Control control, Point pos)
       bei ServerView.Main.m_notifyIcon_Click(Object sender, EventArgs e) in C:\Users\Lutz.KTC\Desktop\Code-ServerView\ServerView\Main.xaml.cs:Zeile 119.
       bei System.Windows.Forms.NotifyIcon.OnClick(EventArgs e)
       bei System.Windows.Forms.NotifyIcon.WmMouseUp(Message& m, MouseButtons button)
       bei System.Windows.Forms.NotifyIcon.WndProc(Message& msg)
       bei System.Windows.Forms.NotifyIcon.NotifyIconNativeWindow.WndProc(Message& m)
       bei System.Windows.Forms.NativeWindow.Callback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)
    Mein Quellcode sieht in der Main.cs so aus:
    Code:
     public Main()
            {
                InitializeComponent();
    
                m_notifyIcon = new NotifyIcon();
                m_notifyIcon.BalloonTipText = "ServerView überwacht nun im Hintergrund die Server!";
                m_notifyIcon.BalloonTipTitle = "ServerView";
                m_notifyIcon.Text = "ServerView";
                m_notifyIcon.Icon =
                    new System.Drawing.Icon(Thread.GetDomain().BaseDirectory + @"Icons\SystemTray.ico");
                m_notifyIcon.ContextMenu = new ContextMenu(new MenuItem[] { new MenuItem("Optionen", Option_Click), new MenuItem("Beenden", Close_Click) });
                m_notifyIcon.Click += new EventHandler(m_notifyIcon_Click);
            }
    In der besagten Zeile 119 steht

    Code:
     m_notifyIcon.ContextMenu.Show(new Control(), new Point(0, 0));
    Wird ein Click im Context Menu aus gelöst, leite ich das Event weiter an mein Controller Klasse wo es dann entsprechend verarbeitet wird. Kurioserweise, kommt zwar die Fehlermeldung, aber das Programm stürzt nicht ab und mein Optionsfenster wird trotzdem geöffnet!

    Habt ihr eine Idee, werde nicht so richtig schlau daraus!

    mfg Daniel

  • #2
    Hallo,

    hab mir den Code nicht angeschaut, aber ein NotifyIcon für WPF gibts mit WPF NotifyIcon - CodeProject und das funktioniert super.


    mfG Gü
    "Any fool can write code that a computer can understand. Good programmers write code that humans can understand". - Martin Fowler

    Comment

    Working...
    X