StealthRT
StealthRT

Reputation: 10552

Created WPF DLL but can not seem to get it to work within my WinForm when importing DLL

Hey all I just finished compiling a DLL from a WPF that allows me to post "GROWL NOTIFICATIONS" on the users screen. The code can be found HERE.

The issue I am currently up against is the following (starting with my Winform Code): Imports WPFGrowlNotification

Public Class Form1
    Dim themsg As GrowlNotifiactions

    Private Sub Button1_Click(sender As System.Object, e As System.EventArgs) Handles Button1.Click
        themsg.showNotifiaction("The title here", "notification", "This is the message here")
    End Sub
End Class

I've also added all references it needs in order for the DLL to work:

PresentationCore
PresentationFramework
System.Core
System.Xaml
WindowsBase
WPFGrowlNotifation

However doing all that, when i debug it and push the button, I get the following error on the line:

themsg.showNotifiaction("The title here", "notification", "This is the message here")

A first chance exception of type 'System.Windows.Markup.XamlParseException' occurred in PresentationFramework.dll

Additional information: Provide value on 'System.Windows.Markup.StaticResourceHolder' threw an exception.

If there is a handler for this exception, the program may be safely continued.

And that's on line (on the Show()):

//Show window if there're notifications
 if (Notifications.Count > 0 && !IsActive)
   Show();

The GROWL code is this (just some of it - parts that are only needed here):

 namespace WPFGrowlNotification
 {
   public partial class GrowlNotifiactions
   {
    private const byte MAX_NOTIFICATIONS = 4;
    private int count;
    public Notifications Notifications = new Notifications();
    private readonly Notifications buffer = new Notifications();
    private const double topOffset = 20;
    private const double leftOffset = 380;

    private void MyWindow_Loaded(object sender, RoutedEventArgs e)
    {
        //this.Top = SystemParameters.WorkArea.Top + topOffset;
        //this.Left = SystemParameters.WorkArea.Left + SystemParameters.WorkArea.Width - leftOffset;
    }

    public void showNotifiaction(string strTitle, string strIcon, string strMessage) {
        AddNotification(new Notification { Title = strTitle, ImageUrl = "pack://application:,,,/Resources/" + strIcon + "-icon.png", Message = strMessage });
    }

    private GrowlNotifiactions()
    {
        this.Top = SystemParameters.WorkArea.Top + topOffset;
        this.Left = SystemParameters.WorkArea.Left + SystemParameters.WorkArea.Width - leftOffset;
        InitializeComponent();
        NotificationsControl.DataContext = Notifications;
    }

    public void AddNotification(Notification notification)
    {
        try
        {
            notification.Id = count++;

            if (Notifications.Count + 1 > MAX_NOTIFICATIONS)
                buffer.Add(notification);
            else
                Notifications.Add(notification);

            //Show window if there're notifications
            if (Notifications.Count > 0 && !IsActive)
                Show();
        }
        catch(Exception e)
        {
            MessageBox.Show(e.Message);
        }
    }

Any incite on how to go about fixing this would be great! Thanks!

Upvotes: 0

Views: 232

Answers (1)

Matt
Matt

Reputation: 6050

If you want to use WPF in Windows Forms, you cannot just import the DLL and just use it as WPF and Windows Forms have many differences.

You can use ElementHost Class in Windows Forms to host a WPF control.

MSDN has a article on how to do this: Walkthrough: Hosting a WPF Composite Control in Windows Forms

Upvotes: 1

Related Questions