C#(WPF)とMVVMパターンを使用してアプリケーションをプログラミングしています。このアプリケーションでは、ローカルネットワークのクライアント間で通知を送信できます。クライアントアプリケーションは、それがシステムトレイにそれを置く最小限にするとMVVMパターン(C#/ WPF)を使用してシステムトレイアイコンを変更
:以下の設計例は、私が前に言ってきたものについて説明します。
通知システムの送信は正常に動作します。
私の質問は、クライアント2のアプリケーションが最小化され、クライアント1が通知を送信したときです。クライアント2のシステムトレイアイコンを変更して新しい通知を受け取ったことを通知するにはどうすればいいですか?事前に
おかげ
更新:
通知トライアイコンを作成するためのコードは次のとおりです。
MainWindow.xaml.cs
using ControlPanelNetClient.ViewModel;
using System;
using System.Windows;
using System.Windows.Forms;
namespace ControlPanelNetClient.View
{
/// <summary>
/// Interaction logic for MainWindow.xaml
/// </summary>
public partial class MainWindow : Window
{
readonly ViewModelControlPanel _vm;
private NotifyIcon m_notifyIcon;
private WindowState m_storedWindowState = WindowState.Maximized;
public MainWindow()
{
InitializeComponent();
_vm = new ViewModelControlPanel();
base.DataContext = _vm;
m_notifyIcon = new System.Windows.Forms.NotifyIcon();
m_notifyIcon.BalloonTipText = "Click to open.";
m_notifyIcon.BalloonTipTitle = "KM Control Panel";
m_notifyIcon.Text = "KM Control Panel";
m_notifyIcon.Icon = new System.Drawing.Icon("favicon.ico");
m_notifyIcon.Click += new EventHandler(NotifyIcon_Click);
this.Closed += new EventHandler(MainWindow_Closed);
this.StateChanged += new EventHandler(MainWindow_StateChanged);
}
private void MainWindow_IsVisibleChanged(object sender, EventArgs e)
{
CheckTrayIcon();
}
void MainWindow_Closed(object sender, EventArgs e)
{
_vm.StopListeningThread();
m_notifyIcon.Dispose();
m_notifyIcon = null;
}
void MainWindow_StateChanged(object sender, EventArgs args)
{
if (WindowState == WindowState.Minimized)
{
Hide();
if (m_notifyIcon != null)
{
m_notifyIcon.ShowBalloonTip(1000);
}
}
else
{
m_storedWindowState = WindowState;
}
}
void MainWindow_IsVisibleChanged(object sender, DependencyPropertyChangedEventArgs args)
{
CheckTrayIcon();
}
void NotifyIcon_Click(object sender, EventArgs e)
{
Show();
WindowState = m_storedWindowState;
}
void CheckTrayIcon()
{
ShowTrayIcon(!IsVisible);
}
void ShowTrayIcon(bool show)
{
if (m_notifyIcon != null)
{
m_notifyIcon.Visible = show;
}
}
}
}
を使用してトレイアイコンを作成するためのサンプルコードですか? btw私はdownvoterではない:) – WPFUser
トレイを使用するためにどのようなプラグインを使用しますか?あなたは自分で書きましたか?もしそうなら、私たちを見せてください。 – FCin
NotifyIcon.Iconを変更しました。これは、NotifyIcon(おそらくapp.csまたはmainwindow.cs)を構築する人は、クライアント2のための参照とtcpクライアント(またはその管理タイプ)の両方を保持しなければならないことを意味します。メッセージが来たら、tcpクライアントはアプリケーションの新しい状態に関心があり、それに応じて両方の更新を保持しています。これはコーディングと呼ばれ、まだ存在しない部分を埋めるものです。 – Will