wpf-115778-mvvm-framework-dxbinding-dxevent.md
DXEvent is used when you need to define methods that should be called on an event.
Similar to DXBinding and a standard Binding , DXEvent works with the DataContext object by default.
<StackPanel>
<StackPanel.DataContext>
<local:ViewModel />
</StackPanel.DataContext>
<Button Content="OK" Loaded="{DXEvent Handler='Initialize()'}" />
<Button Content="OK" Loaded="{DXEvent Handler='Initialize(); Load()'}" />
</StackPanel>
public class ViewModel {
public void Initialize() { }
public void Load() { }
}
Public Class ViewModel
Public Sub Initialize()
End Sub
Public Sub Load()
End Sub
End Class
The Handler expression is specified with a special language that is described in the following topic: Language Specification.
You can pass any parameter to the calling methods.
<TextBlock x:Name="tb" Text="text"/>
<Button Content="OK" Loaded="{DXEvent Handler='Initialize(@e(tb).Text)'}"/>
public void Initialize(string arg) { }
Public Sub Initialize(arg As String)
End Sub
To access the event sender and event arguments, use the @sender and @args reserved words.
<TextBlock x:Name="tb" Text="text"/>
<Button Content="OK" Loaded="{DXEvent Handler='Initialize(@sender.Content, @args, @e(tb).Text)'}"/>
public void Initialize(object content, RoutedEventArgs args, string text) { }
Public Sub Initialize(content As Object, args As RoutedEventArgs, text As String)
End Sub
The DXEvent extension supports the “ = “ operator.
<Button Click="{DXEvent '@e(checkBox).IsChecked=true'}"/>
Note
DXEvents cannot be used in EventSetters.