Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>One way I can approach your question is: Using EvenHandler in Usercontrol and subscribing to it in mainView. On each say button click in Usercontrol raise the event. </p> <p>I just created a sample:</p> <p>we have textbox and button in Usercontrol</p> <p>this is code-behind;</p> <pre><code> public partial class UserControl1 : UserControl { public event EventHandler&lt;EventArgs&gt; CreateNewUserControl = null; public static int InstanceCount = 0; public UserControl1() { InitializeComponent(); Loaded += new RoutedEventHandler(UserControl1_Loaded); } void UserControl1_Loaded(object sender, RoutedEventArgs e) { InstanceCount++; txtControl.Text = "Control - " + InstanceCount; } private void Button_Click(object sender, RoutedEventArgs e) { var handler = CreateNewUserControl; if (handler != null) handler.Invoke(sender,e); } } </code></pre> <p>In MainView:</p> <p>Xaml:</p> <pre><code> &lt;StackPanel x:Name="UserControlTest" Orientation="Vertical" VerticalAlignment="Top" HorizontalAlignment="Right" Grid.Column="1" Grid.RowSpan="2" ScrollViewer.VerticalScrollBarVisibility="Auto" MaxHeight="800" Margin="30"&gt; &lt;RadChartProject:UserControl1 x:Name="UserControl1"/&gt; &lt;/StackPanel&gt; </code></pre> <p>xaml.cs:</p> <pre><code> public MainPage() { InitializeComponent(); UserControl1.CreateNewUserControl += UserControl1_CreateNewUserControl; } void UserControl1_CreateNewUserControl(object sender, EventArgs e) { if(UserControlTest != null) { var control = new UserControl1(); control.CreateNewUserControl += UserControl1_CreateNewUserControl; UserControlTest.Children.Add(control); } } </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload