.NET Framework Developer Center >
.NET Development Forums
>
Windows Presentation Foundation (WPF)
>
Implementing plugin system with image notifications
Implementing plugin system with image notifications
- Hello Again,
i encountered a new problem. What i wanna do is that i have a plugin system (found over the net) and to be able to use images as notifications from the plugin.
I wrote a weather plugin (TrayGadget) that checks for weather updates in every minute. I have a main wpf window on which i have a stackpanel control (TrayGadgetStack). I want to add the Gadget's IconImage as an image to the stack and i want my gadget to update this image on the main window when the weather (and the matching image) changes. Eg i want to display clouds if the weather is cloudy, but when the sun comes out, i want the image to be changed to a sun image - and the code should be in the plugin's code.
Here's some code:
the plugin interface:
Now the WeatherPlugin as follows:Imports System.Windows.Controls Public Interface TrayGadget Sub LoadFunction() Property IconImage() As Image End Interface
Imports System.Windows.Threading Imports System.Runtime.InteropServices Imports System.Windows Imports System.Windows.Media.Imaging Imports System.Xml Imports System.Windows.Controls Public Class TrayGadget Implements TrayGadgetInterface.TrayGadget Dim timer As New System.Windows.Threading.DispatcherTimer Dim _IconImage As New Image Private Sub Update() 'do the update of the current conditions and get the image that matches, raise and image changed event to be able to change the image on the parent form End Sub Private Sub TimerTick(ByVal sender As Object, ByVal e As System.EventArgs) Try Me.Update() Catch ex As Exception Me.IconImageSource = My.Application.Info.DirectoryPath & "\images\no_network.png" End Try End Sub Public Sub LoadFunction() Implements TrayGadgetInterface.TrayGadget.LoadFunction IconImageSource = "1.png" Me.timer.Interval = New TimeSpan(0, 1, 0) AddHandler timer.Tick, AddressOf TimerTick timer.Start() Update() End Sub Property IconImage() As Image Implements TrayGadgetInterface.TrayGadget.IconImage Get Return _IconImage End Get Set(ByVal value As Image) _IconImage = value End Set End Property End Class
and this is how i call the plugin:
Thanks a lotPrivate Function RunGadget(ByVal path As String) Dim Gadget As TrayGadgetInterface.TrayGadget = LoadGadget(path) If Gadget IsNot Nothing Then Gadget.LoadFunction() Me.TrayGadgetStack.Children.Add(Gadget.IconImage) End If End Function Private Function LoadGadget(ByVal LoadPath As String) As TrayGadgetInterface.TrayGadget Dim NewGadget As TrayGadgetInterface.TrayGadget Try Dim PlugInAssembly As Reflection.Assembly = Reflection.Assembly.LoadFrom(LoadPath) Dim Types() As Type Dim FoundInterface As Type Types = PlugInAssembly.GetTypes For Each GadgetType As Type In Types FoundInterface = GadgetType.GetInterface("TrayGadgetInterface.TrayGadget") If FoundInterface IsNot Nothing Then NewGadget = DirectCast(PlugInAssembly.CreateInstance(GadgetType.FullName), TrayGadgetInterface.TrayGadget) End If Next Catch ex As Exception 'handle exceptions here End Try Return NewGadget End Function
Attila Fogel- Moved byJeff ShanMSFTTuesday, November 03, 2009 10:17 AMwpf question (From:Visual Basic General)
Answers
- Hi Attila Fogel,
The basic scenario here is that you need to refresh the image notification when the weather changes, based on my experience, when you change the data(weather), you raise a event to inform the image to update its source, doing this way, the image notification will be updated according to the weather.
Thanks.
Sincerely.
Jim Zhou -MSFT- Marked As Answer byJim Zhou - MSFTModeratorFriday, November 06, 2009 2:30 PM
All Replies
- Try WPF forum http://social.msdn.microsoft.com/Forums/en-US/wpf/threads
kaymaf
If that what you want, take it. If not, ignored it and no complain - Hi Attila Fogel,
The basic scenario here is that you need to refresh the image notification when the weather changes, based on my experience, when you change the data(weather), you raise a event to inform the image to update its source, doing this way, the image notification will be updated according to the weather.
Thanks.
Sincerely.
Jim Zhou -MSFT- Marked As Answer byJim Zhou - MSFTModeratorFriday, November 06, 2009 2:30 PM
- Hi Attila Fogel,
Have you tried the suggestion I posted above?Did that make sense in your scenario? If you still have any issues with this, please feel free to feed back.
Thanks.
Sincerely.
Jim Zhou -MSFT - Hey,
sorry for not posting till now, but yeah, i figured it out by myself, and what you mention is exactly what i'm doing. :) thnx
Attila Fogel - Hi Attila Fogel,
Glad to see that your issue was resolved yet, any questions regarding WPF, please feel free to post on this forum, then we can discuss it.
Thanks.
Sincerely.
Jim Zhou -MSFT


