Hi,@B M-A . Viorel-1's answer is good, I made the example below. Please let me know if there are any questions.
Project structure:
Add reference WpfApp2 for WpfControlLibrary1 :
Right click on the References
of WpfControlLibrary1 -> select Add References...
-> check WpfApp2 and click OK.
UserControl:
<UserControl x:Class="WpfControlLibrary1.UserControl1"
...
>
<StackPanel Background="AliceBlue">
<Button x:Name="window1" Content="window1" Click="window1_Click" Width="100" Height="40"/>
<Button x:Name="window2" Content="window2" Click="window2_Click" Width="100" Height="40"/>
</StackPanel>
</UserControl>
UserControl.xaml.cs:
public partial class UserControl1 : UserControl
{
public UserControl1()
{
InitializeComponent();
}
Window2 win2;
Window1 win1 ;
private void window1_Click(object sender, RoutedEventArgs e)
{
win1 = new Window1();
win1.Show();
}
private void window2_Click(object sender, RoutedEventArgs e)
{
win2 = new Window2();
win2.Show();
win1.Close();
}
}
Add reference WpfControlLibrary1 for WpfApp3 :
Right click on the References of WpfApp3->select Add References...->check WpfControlLibrary1 and click OK.
<Window x:Class="WpfApp3.MainWindow"
>
<Grid>
<uc:UserControl1 Width="300" Height="160"/>
</Grid>
</Window>
The result:
----------------------------------------------------------------------------
If the response is helpful, please click "Accept Answer" and upvote it.
Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.