I am currently trying to add functionality to a ResourceDictionary, by declaring it's x:Class and linking an On Click event to a function within said class. Here is an example:
Where I link an x:Class function to an On Click event:
And the source for my x:Class:
using System;
using System.Windows;
namespace VoidwalkerEngine.Editor.Resources.Themes.Styles
{
public partial class VoidwalkerCellBrowserTreeView : ResourceDictionary
{
public VoidwalkerCellBrowserTreeView()
{
InitializeComponent();
}
private void BaseTreeView_NewFolder_Click(object sender, RoutedEventArgs e)
{
Console.WriteLine("Test"); // This should be fired when I click on "New Folder"
}
}
}
A picture of the menu item just before I click it:
After I click the menu item, it should print "Test" to the console. However, nothing happens. Clearly, I must be doing something wrong. I also found a similar question to mine located here: Control event not firing from class linked to resource dictionary wpf
And their suggestion was to add an extra line to the .csproj file, which I did:
However, this still is not working. Obviously I'm still not linking something correctly, I'm just at a loss of how to proceed from here. Does anyone know how to properly link a ResourceDictionary with it's x:Class? My project is throwing no errors, and Visual Studio even auto-completed the BaseTreeView_NewFolder_Click
function into the x:Class file, so I know the source file itself is attached just fine.
EDIT 1: Here is the full XAML ResourceDictionary: https://pastebin.com/8UepKGTa
EDIT 2: After testing a few things, I noticed something very peculiar. Apparently, any console command I place in the default constructor will be fired, but no methods will be fired. Here is an image:
I'm seriously at a loss right now. The class IS linking just fine, but for whatever reason, the functions won't link to it.