Search code examples
wpfevents.net-4.5markup-extensionswpf-4.5

Markup Extensions for Events in .Net 4.5


WPF does not define a markup extension to be used for events, third parties are able to create a markup extension that can be used with events. Now WPF 4.5 supports markup extensions for events. Can anyone help how to achieve this in .Net 4.5 with an elegant example?


Solution

  • Event markup extensions allow you to use markup extensions for events, where up until WPF 4.5 they were only available for properties. For example:

    <Canvas ClipToBounds="True" Background="White"
            MouseLeftButtonDown="{local:EventToCommand StartPaintCommand}"
            MouseMove="{local:EventToCommand AddLineCommand}"
            MouseLeftButtonUp="{local:EventToCommand EndPaintCommand}">
    </Canvas>
    

    A complete example can be found here.