1

I have WPF window Title-property binded to ViewModel ReadOnly property as:

Title="{Binding ClientAndDate}"

ViewModel property looks like this:

Public ReadOnly Property ClientAndDate As String
    Get
       Return SelectedClient.Name) & " " & SelectedClient.Date)
    End Get
End Property

I have INotifyPropertyChanged implemented in ViewModel but since this is ReadOnly property how it will notify the UI to update when either SelectedClient.Name or SelectedClient.Date is changed?

2
  • I don't think that readonly will effect the INotifyPropertyChanged behavior? Are you facing any issue? Commented Apr 3, 2013 at 12:53
  • Yes but he must informate UI abaout change. i.e. he have to call changet event. Commented Apr 3, 2013 at 12:55

2 Answers 2

3

If you subscribe to the PropertyChanged event of SelectedClient, you could then raise the property change event in the viewmodel on the ClientAndDate property whenever Name or Date are the cause of the property change from SelectedClient.

Even though the ClientAndDate property is read only, raising a property change notification for it anywhere in your viewmodel will cause the binding subsystem to refresh itself from the property.

Sign up to request clarification or add additional context in comments.

1 Comment

Yes, this is what I was using already. Just thought this is not the best practice since it can become pretty messy code to manage when there are lots of those read-only properties. Researched also this elsewhere and seems there are really no fully elegant solutions to this.
-1

You have to make some "notify" method.

Like this one.

protected void OnPropertyChanged(string name)
{
     PropertyChangedEventHandler handler = PropertyChanged;
     if (handler != null)
     {
         handler(this, new PropertyChangedEventArgs(name));
     }
}

And call it with "ClientAndDate" argument every tyme you need update UI.

"ClientAndDate" is name of property that was updated.

Here is whole example with GET statement but you can use it same way.

5 Comments

Ôo I don't understand it. How should this method be useful, if it's implemented in a view class?
Then your first sentence is misleading You have to make some "notify" method in your page/window class. I didn't follow your link.
No. Is this method is propertyChanged event called. handler(this, new PropertyChangedEventArgs(name));
I know what the rest of your post is meaning. But the first sentence is still misleading, since you're talking of a page/window class. You must only rephrase it and everything will be fine... ;o)
Oh. Yes. You are right. I forget that he want this in ViewModel. Sorry ;D

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.