I just wanted to share a simplified version of a wrapper service for the DesktopAlert that we use to handle Images from multiple sources - see below.
I trust that someone will find this useful.
Enjoy!
Graeme
1. Resource Image references
1.<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"2. xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">3. <BitmapImage x:Key="MailImage" UriSource="Images/Mail.png" />4. <BitmapImage x:Key="ContactImage" UriSource="Images/Contact.png" />5.</ResourceDictionary>
2. Type References to images
1.public enum AppAlertIconType2.{3. Mail,4. Contact,5. Url = -16.}
3. Alert service interface (we use MEF)
1.public interface IAppAlertService2.{3. void ShowMessage(string header, string content, string imageUrl, int showDuration = 5000, double width = 48, double height = 48);4. void ShowMessage(string header, string content, AppAlertIconType icon, string imageUrl = "", int showDuration = 5000, double width = 48, double height = 48);5. void ShowMessage(string header, string content, Image image, int showDuration = 5000, double width = 48);6. void CloseAllAlerts();7.}
4. Alert Service
01.public class AppAlertService : IAppAlertService02.{03. RadDesktopAlertManager manager = new RadDesktopAlertManager(AlertScreenPosition.TopRight);04. 05. public void ShowMessage(string header, string content, string imageUrl, int showDuration = 5000, double width = 48, double height = 48)06. {07. this.ShowMessage(header, content, AppAlertIconType.Url, imageUrl, showDuration, width, height);08. }09. 10. public void ShowMessage(string header, string content, AppAlertIconType icon, string imageUrl = "", int showDuration = 5000, double width = 48, double height = 48)11. {12. Func<AppAlertIconType, Image> GetResourceImage = new Func<AppAlertIconType, Image>(t => new Image { Source = Application.Current.FindResource(string.Format("{0}Image", t.ToString())) as ImageSource, Width = width, Height = height });13. Func <string, Image> GetWebImage = new Func<string, Image>(t => new Image { Source = new BitmapImage(new Uri(t, UriKind.Absolute)), Width = width, Height = height });14. this.ShowMessage(header, content, icon == AppAlertIconType.Url ? GetWebImage(imageUrl) : GetResourceImage(icon), showDuration, width);15. }16. 17. public void ShowMessage(string header, string content, Image image, int showDuration = 5000, double width = 48)18. {19. manager.ShowAlert(new DesktopAlertParameters20. {21. Header = header,22. Content = content,23. Icon = image,24. IconColumnWidth = width,25. IconMargin = new Thickness(10, 0, 20, 0),26. ShowDuration = showDuration27. });28. }29. 30. public void CloseAllAlerts()31. {32. manager.CloseAllAlerts();33. }34.}
5. Usage
1.IAppAlertService alertService = new AppAlertService();2.alertService.ShowMessage("header", "content goes here", AppAlertIconType.Mail);3.alertService.ShowMessage("header", "content goes here", AppAlertIconType.Url, "http://greywolf.critter.net/images/gallery/critters/2007-09-14-happy-pink-unicorn.jpg");