this markup help you to update the target of a markup extension after the initial evaluation.
UpdatableMarkupExtension
Located in the HandyControl.Tools namespace.
1 | Using HandyControl.Tools; |
Example
Let’s assume we want to create a custom markup extension which indicates whether the network is available. It would be used like that :
1 | <CheckBox IsChecked="{local:NetworkAvailable}" Content="Network is available" /> |
Obviously, we want the checkbox to be updated when the availability of the network changes (e.g. when the network cable is plugged or unplugged, or when the Wifi network is out of reach). So we need to handle the NetworkChange.NetworkAvailabilityChanged
event, and update the IsChecked
property accordingly. So the extension will inherit the UpdatableMarkupExtension
class to take advantage of the UpdateValue
method :
1 | public class NetworkAvailableExtension : UpdatableMarkupExtension |
We subscribe to the NetworkAvailabilityChanged
event in the class constructor. If we wanted to subscribe to an event of the target object, we would have to do it in the ProvideValueInternal method, so that the target object can be accessed.