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 1011435
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T09:14:02+00:00 2026-05-16T09:14:02+00:00

I have a class Wizard which creates a wizard with pages defined in the

  • 0

I have a class Wizard which creates a wizard with pages defined in the same project. The PageViewModel is separated from PageView. PageViewModel is an ordinary C# class derived from PageViewModelBase abstract class and PageView is a UserControl. In order to define a mapping between PageViewModel and PageView I wrote the following code for every page in my project:

 <Window.Resources>
    <DataTemplate DataType="{x:Type OurNewPageViewModel}">
      <OurNewPageView />
    </DataTemplate>
  </Window.Resources>

Now I want to add pages to wizard when the users’ code calls my Wizard’s constructor. It means to move Pages View and ViewModel to the user side. For instance, in order to create a wizard with one page user will write the following code:
Wizard usersWizard = new Wizard(new usersViewModel(), new userView());
The problem is I don’t know how to provide the mapping between viewModel and View in my constructor. As far as I understand I can use two different approaches to solve this problem. First, to use FrameworkElementFactory but the following code doesn’t work:

        //let we have WelcomePageView wpview and WelcomePageViewModel wpviewmodel

        FrameworkElementFactory fef = new FrameworkElementFactory(wpview.GetType());
        DataTemplate dt = new DataTemplate();
        dt.DataType = wpview.GetType();

        dt.VisualTree = fef;

        base.Resources.Add(wpviewmodel.GetType(), dt);

Second, to use XamlReader. I can create a data template using it but I don’t know how to attach it to resources.

  • 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-05-16T09:14:03+00:00Added an answer on May 16, 2026 at 9:14 am

    In your code-behind to create the DataTemplate, there are a couple of errors:

    1. “dt.DataType = wpfView.GetType()” should be “dt.DataType = wpfviewmodel.GetType()”
    2. You should use a DataTemplateKey when adding the template to the ResourceDictionary.

    So your code should be something like:

    DataTemplate dt = new DataTemplate();
    dt.DataType = typeof(PageViewModel);
    FrameworkElementFactory fef = new FrameworkElementFactory(typeof(PageView));
    dt.VisualTree = fef;
    DataTemplateKey dtKey = new DataTemplateKey(typeof(PageViewModel));
    this.Resources.Add(dtKey, dt);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 492k
  • Answers 492k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer Here's one example: /* Create the stored procedure */ create… May 16, 2026 at 10:29 am
  • Editorial Team
    Editorial Team added an answer This piece of code solved my problem: var domain =… May 16, 2026 at 10:29 am
  • Editorial Team
    Editorial Team added an answer I may be off the mark, but if you are… May 16, 2026 at 10:29 am

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

Related Questions

I have a class which derived from the TableLayoutPanel. This class makeup the tabel
I have an ALPHA application which allows you grab an obfuscated font from and
I have a class on which I'd like to define a unique key using
I've got a wizard which needs to validate if a user is logged in
I have a MFC wizard based application (CPropertySheet, CPropertyPage) created with vS2008. I am
I have class representing a unit of measure with a Decimal as the numeric.
I have a serious question for you guys. I am working on a project
I have a class similar to the one below. How do I call my
I have a class as follows: public class Polygon extends Shape{ private int noSides;
I have a class public class Item : IItem { public virtual Guid Id

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.