Let's say I have a property called Greeting
that is principally composed of two bound properties: LastName
and FirstName
. Can I subscribe to updates on first and last name so I can force a refresh with OnPropertyChanged()
for my Greeting property. Here's a simple example:
View
<!-- language: lang-xml --><TextBox Text="{Binding FirstName}" />
<TextBox Text="{Binding LastName}" />
<TextBlock Text="{Binding Greeting}" />
ViewModel
<!-- language: lang-vb -->Public Property FirstName() As String
Get
Return _firstName
End Get
Set(ByVal value As String)
_firstName = value
OnPropertyChanged("FirstName")
End Set
End Property
'... Omitting LastName for brevity ...
Public ReadOnly Property Greeting() As String
Get
Return String.Format("Hello {0} {1}", Firstname, LastName)
End Get
End Property
The way this is currently set up, nothing will ever update the Greeting binding. I could put OnPropertyChanged("Greeting")
in the setter for FirstName
and LastName
, but this feels wrong. In a more complex example, I'd rather each object just take care of refreshing itself when something changes.
Q:) Can I force an update for a ReadOnly
Property when one of the Properties it's composed of changes?