Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8608737
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T03:41:37+00:00 2026-06-12T03:41:37+00:00

I am new in MVVM/WPF, I was studying web examples for last two weeks

  • 0

I am new in MVVM/WPF, I was studying web examples for last two weeks but still I couldn’t find out how to deal with following thing:

I am working on some sort of “defect inserting software” for our manufacturing department in company.
User can “create new record”, then based on user’s choice different UserControls with different Questions/RadioButtons/ComboBoxes are displayed.

I inspired with great article about Internationalized Wizard , but the wizard in this example is really simple and straightforward.

Following code creates my first wizard steps:

 void CreatePages()
 {
      var welcomePage = new WelcomePageViewModel();
      var settings = new SettingsViewModel();
      var cellScrap = new WizardChooseCellScrapGradeViewModel(this.CellScrap);
      var manufacturer = new WizardChooseManufacturerViewModel(this.CellScrap);

      var pages = new List<WizardPageViewModelBase>(); 

      pages.Add(welcomePage);
      pages.Add(settings);
      pages.Add(cellScrap);
      pages.Add(manufacturer);

      _pages = new ReadOnlyCollection<WizardPageViewModelBase>(pages);
 }

Now when user chooses manufacturer A, program should ask him to fill data in usercontrol_1, if he chooses manufacturer B, then usercontrol_2 will be shown.

Whats the best practice to do this? I suppose I cannot use ReadOnlyCollection for this, any better idea?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-12T03:41:38+00:00Added an answer on June 12, 2026 at 3:41 am

    I typically use a ContentControl with the ContentControl.Template being set to whatever Template is needed by a DataTrigger that based on some bound value

    <DataTemplate x:Key="ManufacturerAView" TargetType="{x:Type local:WizardPageViewModelBase}">
        <TextBlock Text="I'm Manufacturer A" />
    </DataTemplate>
    
    <DataTemplate x:Key="ManufacturerBView" TargetType="{x:Type local:WizardPageViewModelBase}">
        <TextBlock Text="I'm Manufacturer B" />
    </DataTemplate>
    
    <ContentControl Content="{Binding }">
        <ContentControl.Style>
            <Style TargetType="{x:Type ContentControl}">
                <Style.Triggers>
                    <DataTrigger Binding="{Binding Manufacturer}" Value="A">
                        <Setter Property="ContentTemplate" Value="{StaticResource ManufacturerAView}" />
                    </DataTrigger>
                    <DataTrigger Binding="{Binding Manufacturer}" Value="B">
                        <Setter Property="ContentTemplate" Value="{StaticResource ManufacturerBView}" />
                    </DataTrigger>
                </Style.Triggers>
            </Style>
        </ContentControl.Style>
    </ContentControl>
    

    This will only work if your ManufacturerViewModel is the same regardless of which Manufacturer is selected.

    If it’s different, I would attach a PropertyChange event to the ChooseManufacturerViewModel that would add a specific ManufacturerViewModel to the collection whenever the SelectedManufacturer property changes.

    manufacturer.PropertyChanged += ChooseManufacturer_PropertyChanged;
    pages.Add(manufacturer);
    
    ....
    
    void ChooseManufacturer_PropertyChanged(object src, PropertyChangedEventArgs e)
    {
        if (e.PropertyName == "SelectedManufacturer")
        {
            switch ((WizardChooseManufacturerViewModel)src).SelectedManufacturer)
            {
                // You'll want to check any existing ManufactorerViewModels 
                // and remove them as well if needed
                case "A":
                    Pages.Add(new ManufacturerAViewModel);
                    break;
    
                case "B":
                    Pages.Add(new ManufacturerBViewModel);
                    break;
            }
        }
    }
    

    For the UI to be correctly notified that the new page has been added, you’ll want to make Pages of type ObservableCollection<WizardPageViewModelBase> instead of a ReadOnlyCollection

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Being new to both WPF and MVVM, I'm studying Josh Smith's article on the
I'm new to Prism, but I have successfully built several WPF/Mvvm-Light applications. I'm using
I'm not new to WPF or C# but I am new to MVVM and
I am reasonably new to WPF and MVVM but I understand the basics. The
public DEV_MasterPOSEntities Context = new DEV_MasterPOSEntities(); I am using WPF and MVVM but system
I am new to WPF and MVVM, and I am working on an application
I'm using MVVM in a WPF app. I'm very new to both. Let me
I'm pretty new to WPF and using the MVVM design pattern. To help learn
I just started developing my brand new windows 8 application last week using mvvm
I am new to MVVM/WPF and know how to use Grid and StackPanel layout

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.