One way to add a dynamic control in code-behind is something like this (obviously):
Button thisButton = new Button();
thisButton.Name = "somecool_btn";
thisButton.Content = "Click Me";
someStackPanel.Children.Add(thisButton);
I used to know how to do this using XAML in code behind for more complex dynamic control creation. Basically by creating a string with xaml and then adding it to the StackPanel (or some other UI element)....
string someXaml = @"<Button x:Name='somecool_btn' Content='Click Me' Width='100' Height='29'></Button>";
Now add someXaml to a StackPanel or something...
You can use XamlReader.Parse(https://learn.microsoft.com/dotnet/api/system.windows.markup.xamlreader.parse?view=netcore-3.1). Below is actual usage of it in my previous project(It's messy).