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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T22:09:41+00:00 2026-05-25T22:09:41+00:00

In my WPF app, I use a WCF service to fetch data. So naturally,

  • 0

In my WPF app, I use a WCF service to fetch data.
So naturally, at some point i had “complex” objects that require a DataContract to be passed as a whole to the WPF app.

Now of course, I need to respond to changes, and I implement INotifyPropertyChanged on my ViewModels, however since some objects are actually DataContracts, I would have to recompose those so that they implement INotifyPropertyChanged.

I feel like it’s messy.

What i tried to do is implement the interface directly on the DataContract definition, but I can’t react properly to a change.
For example, if a Two-Way databound TextBox has its text changed, my ViewModel should react to it by changing the value in the corresponding SQL table (through the WCF service), but since the object is defined on WCF side, I can’t do that in the setter of the property.

What I do for now, is subscribe to the PropertyChanged event of the DataContracts, and use reflection to know which property changed and its new value.
But those objects are held in an ObservableCollection<T>, that’s a lot of events, and it feels very brittle… what if i add/remove an element from the collection for example?

I do it like this (this is bad I think):

foreach (ImageInfo imgi in (param.Images as ObservableCollection<ImageInfo>))
{
    imgi.PropertyChanged += (sender, args) =>
        {
            object newValue = Tools.GetProperty((sender as ImageInfo), args.PropertyName);
        };
}

And then I’d send it back to the WCF service.

Is there a more elegant solution to this? should I implement INotifyPropertyChanged on the ViewModel only, and recompose the DataContracts instead?

Thanks!

  • 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-25T22:09:42+00:00Added an answer on May 25, 2026 at 10:09 pm

    Alright so after some time thinking it through, I implemented it like this for now but it might change because I meet with an expert next monday (I’ll update if he gives me a better idea).

    1) The WCF service has a DataContract such as:

    [DataContract]
    public class MyWcfData : INotifyPropertyChanged
    {
        public MyWcfData()
        {
           MyField = "";
        }
    
        [DataMember]
        public string MyField;
    
        [DataMember]
        public string MyFieldModified;
    }
    

    Note: INotifyPropertyChanged is implemented the usual way, i just left it out for readability, and because i dont have my snippets on this computer.

    When GetMyData() is called on the service, it returns an instance of that class, with only “MyField” populated. MyFieldModified is left to null.

    On my DAL (so client-side), where MyWcfData is recieved:

    public class MyDAL
    {
       //... some init code
       public MyWcfData GetMyWcfData()
       {
          MyWcfData newData = m_WcfService.GetMyData();
          newData.MyFieldModified = newData.MyField;
          return newData;
       }
    }
    

    The point here is that the data needs to be duplicated so that i can keep track of changes, and only update a property once in the end, even if the user changed it 10 times (i just compare everytime to the original value). But I don’t want to send duplicated data over the wire, so instead i do the duplication in the DAL, before any business object has access to it.

    On the ViewModel of my view:

    public class MyViewModel
    {
       //.. some init code
               DelegateCommand<MyWcfData> _GetDataCommand;
            public DelegateCommand<MyWcfData> GetDataCommand
            {
                get
                {
                    if (_GetDataCommand == null)
                        _GetDataCommand = new DelegateCommand<MyWcfData>(GetData);
                    return _GetDataCommand;
                }
            }        
            public void GetData(MyWcfData param)
            {
                m_WcfData = m_DAL.GetMyWcfData();
            }  
    }
    

    And then last but not least, in my XAML, i bind to MyFieldModified (in Two-Way binding) in a TextBox.
    I then use System.Windows.Interactivity to call a DelegateCommand upon the TextChanged event.
    When that last command is fired, i put the change in a Queue (to keep track of the changes order) and i send it back to the Wcf service for data persistency when the user presses a Save button.

    Note: I actually use a custom-made ObservableQueue<T> so that i can keep track of the number of changes and enable the save button accordingly through binding. I will make a blog post about it so stay tuned 😉

    Note2: I gave up on making it save every tiny change made instantly, even though in this case it would have worked because it’s not a feature much used, and few changes are expected; but as pointed out in other answers it’s bad practice.

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

Sidebar

Related Questions

We have some applications (web and WPF) that call WCF services to access data.
I have a WPF app that makes use of some multi threading. I am
I'm trying to use WindowsFormsHost in a WPF app so I can use some
I've got a WPF windows client that calls a WCF web service. The user
I have to use Sync Framework 2.0 in our WPF app that will contain
I recently refactored a WPF app so that it no longer wraps each use
There are two projects in one VS solution: client(wpf app) and а wcf service
I have written a code for my WPF App to use WCF, wcf is
Background: We have a ClickOnce-deployed WPF app, that talks to WCF Services, which in
I am trying to use Windows.Media.Capture.CameraCaptureUI() of Metro Style app in WPF application in

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.