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

  • SEARCH
  • Home
  • 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 6951315
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T14:12:14+00:00 2026-05-27T14:12:14+00:00

I’m trying to insert some design data in a control by temporarily setting datacontext

  • 0

I’m trying to insert some design data in a control by temporarily setting datacontext in xml. The contents are defined by the following class:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Practices.Prism.ViewModel;
using AITReportEditor.Infrastructure.Models;
using System.Collections.ObjectModel;

namespace AITReportEditor.Infrastructure.Models
{
    public class ComponentItem : NotificationObject
    {

        //Constructor for expression Blend sample data
        public ComponentItem() { }

        public ComponentItem(AITReportEditor.Infrastructure.Models.Component copyItem)
        {
            this.PartData = new PartDataItem(copyItem.PartData);
            this.ObjectId = copyItem.ObjectId;


            Files = new ObservableCollection<FileItem>();
            foreach (File existItm in copyItem.Files)
            {
                FileItem fileItem = new FileItem(existItm);
                Files.Add(fileItem);
            }

            SpareParts = new ObservableCollection<SparepartItem>();
            foreach (Sparepart existItm in copyItem.Spareparts)
            {
                SparepartItem sparepartItem = new SparepartItem(existItm);
                SpareParts.Add(sparepartItem);
            }
        }



        private ObservableCollection<FileItem> _files;
        public ObservableCollection<FileItem> Files
        {
            get { return _files; }
            set
            {
                _files = value;
            }

        }

        private ObservableCollection<SparepartItem> spareparts;
        public ObservableCollection<SparepartItem> SpareParts
        {
            get { return spareparts; }
            set
            {
                spareparts = value;
            }

        }



        private string _objectid;
        public string ObjectId
        {
            get { return _objectid; }
            set
            {
                if (!value.Equals(_objectid))
                {
                    _objectid = value;
                    this.RaisePropertyChanged(() => this.ObjectId);
                }

            }
        }

        private PartDataItem _partdata;
        public PartDataItem PartData
        {
            get { return _partdata; }
            set
            {
                if (!value.Equals(_partdata))
                {
                    _partdata = value;
                    this.RaisePropertyChanged(() => this.PartData);
                }

            }
        }
    }
}

and

namespace AITReportEditor.Infrastructure.Models
{
    public class PartDataItem : NotificationObject
    {

        public PartDataItem() { }



        public PartDataItem(InspectionObject copyItem)
        {

            this.Name = copyItem.Name;
            this.Note = copyItem.Note;
            this.Status = copyItem.Status;

        }


        private string _name;
        public string Name
        {
            get { return _name; }
            set
            {
                if (!value.Equals(_name))
                {
                    _name = value;
                    this.RaisePropertyChanged(() => this.Name);
                }

            }

        }


        private string _note;
        public string Note
        {
            get { return _note; }
            set
            {
                if (!value.Equals(_note))
                {
                    _note = value;
                    this.RaisePropertyChanged(() => this.Note);
                }

            }

        }

        private int _status;
        public int Status
        {
            get { return _status; }
            set
            {
                if (!value.Equals(_status))
                {
                    _status = value;
                    this.RaisePropertyChanged(() => this.Status);
                }

            }

        }
    }
}

In xaml i define datacontext with

xmlns:inf="clr-namespace:AITReportEditor.Infrastructure.Models;assembly=AITReportEditor.Infrastructure"

<UserControl.DataContext>
        <inf:ComponentItem>
            <inf:ComponentItem.ObjectId>1212</inf:ComponentItem.ObjectId>
            <inf:ComponentItem.PartData>
                <inf:ComponentItem.PartData.Name>klas</inf:ComponentItem.PartData.Name>
            </inf:ComponentItem.PartData>



        </inf:ComponentItem>

    </UserControl.DataContext>

The ObjectId works fine, but I can’t seem to define the partdata. Anyone know what I’m doing wrong?

[UPDATE] Made some changes

Instead of defining sampledata insiede usercontrol datacontext I’m setting design data in the external file and changing xaml to

<Grid Background="Transparent" d:DataContext="{d:DesignDataSource=./../../SampleData/SampleData.xaml}">

in the control and defining sample data in seperate file

<m:ComponentItem xmlns:m="clr-namespace:AITReportEditor.Infrastructure.Models;assembly=AITReportEditor.Infrastructure"
                 ObjectId="12321">
    <m:ComponentItem.PartData Name="Klas" />

</m:ComponentItem>

But I’m still getting “Cannot set property on element…” when I try to add PartData to sample file.

Anyone?

  • 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-27T14:12:14+00:00Added an answer on May 27, 2026 at 2:12 pm

    THink i solved it, seems to be all in the syntax for typed classes probaly obscurely hidden away in yet another book i haven’t read. To solve it i made a simpler projet with 3 classes Person, Invoice and ContactInfo

     public class Person
        {
            public Person()
            { }
    
    
            public string Name { get; set; }
    
            public List<Invoice> Invoices{get; set;}
    
            public ContactInfo ContactInfo { get; set; }
    
        }
    
         public class Invoice
            {
                public int Amount { get; set; }
        }
    
     public class ContactInfo
        {
    
            public ContactInfo()
            {
    
            }
            public string Adress { get; set; }
        }
    

    The syntax for the design data that works is then

    <m:Person xmlns:m="clr-namespace:WpfApplication2" Name="Klas">
        <m:Person.Invoices>
            <m:Invoice Amount="12" />
            <m:Invoice Amount="12" />
            <m:Invoice Amount="12" />
        </m:Person.Invoices>
        <m:Person.ContactInfo>
            <m:ContactInfo Adress="Lena"></m:ContactInfo>
        </m:Person.ContactInfo>
    </m:Person>
    

    Notice that if you want to use the list invoices you have to add

    private List<Invoice> _invoices = new List<Invoice>();
            public List<Invoice> Invoices
            {
                get { return _invoices; }
                set { _invoices = value; }
            }
    

    in the class.

    Hope this could be of value to someone else.

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

Sidebar

Related Questions

I have some data like this: 1 2 3 4 5 9 2 6
I am trying to understand how to use SyndicationItem to display feed which is
Basically, what I'm trying to create is a page of div tags, each has
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have just tried to save a simple *.rtf file with some websites and
For some reason, after submitting a string like this Jack’s Spindle from a text
I'm using v2.0 of ClassTextile.php, with the following call: $testimonial_text = $textile->TextileRestricted($_POST['testimonial']); ... and
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
We are using XSLT to translate a RIXML file to XML. Our RIXML contains
I'm trying to decode HTML entries from here NYTimes.com and I cannot figure out

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.