I create a templated RadioButton at run time. After initializing the templated RadioButton, I set the DataContext and Tag property and then add this button in a StackPanel. The problem is that the template binding does not work. below is the XAML and the code behind. All this work if I assign values to these properties in XAML. Any ideas?
Code: TemplatedRadioButton commandButton = new TemplatedRadioButton(); commandButton.DataContext = "bla"; // Some txt that I will. commandButton.Tag = MyImage; // This is the ImageIcon that I create at run time too. MyStackPanel.Children.Add(commandButton);
XAML: