I created a WPF application in which I dynamically create XAML elements using C # code, and then add them to the root "container" grid.
What I'm trying to do is take advantage of Blend and create some XAML pages that have their own set of code behind the logic, Storyboards, etc.
I want to load this XAML at runtime, but for some reason my approach does not work, and I do not understand why.
This is what I did before. In my root window, I create a new MyModule and add it to my contentRoot.
myModule = new MyModule();
contentRoot.Children.Add(myModule );
(The approach that works) The MyModule class extends Canvas and consists of a .XAML file and .CS code behind the file. XAML is just the root canvas, and .CS has all the logic for creating elements and adding them to the root canvas.
When I use the same approach in which MyModule now continues, the page does not appear. XAML now has a lot of content, including Canvas.Resources Canvas.Triggers and many other elements.
How can I load pre-created XAML content from a class, including the code behind the logic at runtime?
source
share