我有一個用c#編寫的程序,它包含一個帶有可觀察集合的列表框。當收藏中添加了一個項目時,我需要爲用戶彈出一個氣球(在系統托盤中)。我有一個包含了在添加項目通知列表框的方法的類(見下文):在類之間共享對象
void OnFileCreated(object sender, FileSystemEventArgs e)
{
if (!base.Dispatcher.CheckAccess())
{
base.Dispatcher.BeginInvoke(
DispatcherPriority.Normal,
(FileSystemEventHandler)OnFileCreated,
sender, e);
}
else
{
// Ignore new directories.
if (File.Exists(e.FullPath))
{
Debug.WriteLine("File Created: " + e.FullPath);
_files.Add(new ObservableFileInfo(e.FullPath));
//Alert users to new request
string title = "Access Request";
string text = "A new access request has been submitted";
//show balloon with built-in icon
tbi.ShowBalloonTip(title, text, BalloonIcon.Error);
}
}
}
代碼工作完全一樣的事實打算分開,如果我創建一個新的氣囊將只顯示OnFileCreated方法中氣球的實例(上面沒有看到,因爲我拿出了代碼)。作爲參考,我正在使用以下項目中的系統托盤圖標.dll:http://www.codeproject.com/Articles/36468/WPF-NotifyIcon?fid=1540774&select=4624878&fr=51#xx0xx
我的問題是我已經在MainWindow類中啓動了一個系統托盤圖標,但我無法調用它來顯示氣球我的OnFileCreated方法。我不確定我如何在課堂上「分享」這些信息。
如果有人有任何想法,那就太好了。