c# add user control in wpf project dynamically to other user control programatically

I’m working on a project with several UserControl elements and MVVM. The task is to create a dynamic user interface to prevent using any pop-up windows with Show() or ShowDialog().

EDIT: After several comments (thanks for the feedback) and checking the flow of the text, I decided to edit the text and try to explain more about the task.
In a previous version of this tool everything was handled by separate dialogs and therefore it was possible to create a mess on the screen (not recommended, but possible). The tool is some kind of control center and can dynamically load other sub-modules. So, in the new version my idea was to add a UserControl that can handle two tasks at once: 1. Be some kind of overview for the possible number of sub-modules, 2. Be the receiver of the sub-module UserControls.
I started the test of this construction in my SettingsView and added my new UserControl which hopefully was most dynamic. Image1 is to show the idea behind.

SettingsView.xaml:

<UserControl x:Class="nameXY.Views.SettingsView"
             xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
             xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
             xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 
             xmlns:d="http://schemas.microsoft.com/expression/blend/2008" 
             xmlns:local="clr-namespace:nameXY.View"
             xmlns:vm="clr-namespace:nameXY.ViewModel"
             mc:Ignorable="d" 
             d:DesignHeight="850" d:DesignWidth="500"
             Background="White">
    <UserControl.DataContext>
        <vm:SettingsViewModel />
    </UserControl.DataContext>

    <!-- some code -->

    <UserControl Grid.Column="0"
                 x:Name="ModuleControl">
        <local:CommonUserControlCollectionView/>
    </UserControl>
</UserControl>

Loading this empty UserControl is fine, but filling the content is currently not working. The same UserControl should be able to receive other user controls afterwards in another part of the tool. Those controls would come from external DLLs, but the idea is the same as in the image above.
My original CommonUserControlCollectionView.xaml is:

<UserControl x:Class="nameXY.View.CommonUserControlCollectionView"
             xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
             xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
             xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 
             xmlns:d="http://schemas.microsoft.com/expression/blend/2008" 
             xmlns:local="clr-namespace:nameXY.View"
             xmlns:vm="clr-namespace:nameXY.ViewModel"
             mc:Ignorable="d" 
             d:DesignHeight="450" d:DesignWidth="800">
    <UserControl.DataContext>
        <vm:CommonUserControlCollectionViewModel />
    </UserControl.DataContext>
    <Grid>
        <ScrollViewer VerticalScrollBarVisibility="Auto"
                      HorizontalScrollBarVisibility="Disabled">
            <Grid>
                <Grid.RowDefinitions>
                    <RowDefinition Height="Auto"/>
                    <RowDefinition Height="5"/>
                    <RowDefinition Height="Auto"/>
                    <RowDefinition Height="5"/>
                    <RowDefinition Height="Auto"/>
                    <RowDefinition Height="5"/>
                    <RowDefinition Height="Auto"/>
                    <RowDefinition Height="5"/>
                    <RowDefinition Height="Auto"/>
                </Grid.RowDefinitions>

                <UserControl Grid.Row="0"
                             x:Name="UserControlPanel01"
                             MinHeight="30"/>

                <UserControl Grid.Row="2"
                             x:Name="UserControlPanel02"
                             MinHeight="30"/>

                <UserControl Grid.Row="4"
                             x:Name="UserControlPanel03"
                             MinHeight="30"/>

                <UserControl Grid.Row="6"
                             x:Name="UserControlPanel04"
                             MinHeight="30"/>

                <UserControl Grid.Row="8"
                             x:Name="UserControlPanel05"
                             MinHeight="30"/>
            </Grid>
        </ScrollViewer>
    </Grid>
</UserControl>

As this view is embedded in the SettingsView I then tried to add the controls dynamically in the view model.
SettingsViewModel.cs:

public CommonUserControlCollectionView ModuleControl { get; set; }

private void CallUpdateModuleList()
{
    var _control01 = new ModuleActivationControlView();
    ((ModuleActivationControlView)_control01).InitializeView("TestControl01", false, true);
    ModuleControl.UserControlPanel01.Children.Clear();
    ModuleControl.UserControlPanel01.Children.Add(_control01);
}

In debug mode this works fine, but on the GUI nothing happens. Due to other questions here (like WPF add element… or Usercontrol c# add…) I started testing other approaches (as seen in my first draft) and changed the controls to StackPanel, WrapPanel or ContentControl, but also there nothing changes and I’m sure I’m missing something.

I hope I was able to give a better explanation 🙂 last one was made in a hurry yesterday.

7

Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa Dịch vụ tổ chức sự kiện 5 sao Thông tin về chúng tôi Dịch vụ sinh nhật bé trai Dịch vụ sinh nhật bé gái Sự kiện trọn gói Các tiết mục giải trí Dịch vụ bổ trợ Tiệc cưới sang trọng Dịch vụ khai trương Tư vấn tổ chức sự kiện Hình ảnh sự kiện Cập nhật tin tức Liên hệ ngay Thuê chú hề chuyên nghiệp Tiệc tất niên cho công ty Trang trí tiệc cuối năm Tiệc tất niên độc đáo Sinh nhật bé Hải Đăng Sinh nhật đáng yêu bé Khánh Vân Sinh nhật sang trọng Bích Ngân Tiệc sinh nhật bé Thanh Trang Dịch vụ ông già Noel Xiếc thú vui nhộn Biểu diễn xiếc quay đĩa Dịch vụ tổ chức tiệc uy tín Khám phá dịch vụ của chúng tôi Tiệc sinh nhật cho bé trai Trang trí tiệc cho bé gái Gói sự kiện chuyên nghiệp Chương trình giải trí hấp dẫn Dịch vụ hỗ trợ sự kiện Trang trí tiệc cưới đẹp Khởi đầu thành công với khai trương Chuyên gia tư vấn sự kiện Xem ảnh các sự kiện đẹp Tin mới về sự kiện Kết nối với đội ngũ chuyên gia Chú hề vui nhộn cho tiệc sinh nhật Ý tưởng tiệc cuối năm Tất niên độc đáo Trang trí tiệc hiện đại Tổ chức sinh nhật cho Hải Đăng Sinh nhật độc quyền Khánh Vân Phong cách tiệc Bích Ngân Trang trí tiệc bé Thanh Trang Thuê dịch vụ ông già Noel chuyên nghiệp Xem xiếc khỉ đặc sắc Xiếc quay đĩa thú vị
Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa
Thiết kế website Thiết kế website Thiết kế website Cách kháng tài khoản quảng cáo Mua bán Fanpage Facebook Dịch vụ SEO Tổ chức sinh nhật