c# - Sharing objects between classes -
i have program written in c# contains listbox observable collection. want balloon pop-up user (in system tray) when collection has item added. have class contains method notifying listbox when item added (see below):
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 new request string title = "access request"; string text = "a new access request has been submitted"; //show balloon built-in icon tbi.showballoontip(title, text, balloonicon.error); } } } the code works intended apart fact balloon show if create new instance of balloon within onfilecreated method (not seen above took code out). reference, using system tray icon .dll following project: http://www.codeproject.com/articles/36468/wpf-notifyicon?fid=1540774&select=4624878&fr=51#xx0xx
my issue have system tray icon initiated in mainwindow class, cannot call on show balloon onfilecreated method. not sure how can "share" information across classes.
if has ideas great.
i ended using findresource locate resource defined in xaml resource document. specified in project code referencing to, findresource not working itself, needed add app.current:
notifyicon = (taskbaricon)app.current.findresource("notifyicon"); notifyicon.showballoontip(title, text, balloonicon.error);
Comments
Post a Comment