Back to Devexpress

DXEvent

wpf-115778-mvvm-framework-dxbinding-dxevent.md

latest2.3 KB
Original Source

DXEvent

  • Aug 25, 2023

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.

xaml
<StackPanel>
    <StackPanel.DataContext>
        <local:ViewModel />
    </StackPanel.DataContext>
    <Button Content="OK" Loaded="{DXEvent Handler='Initialize()'}" />
    <Button Content="OK" Loaded="{DXEvent Handler='Initialize(); Load()'}" />
</StackPanel>
csharp
public class ViewModel {
    public void Initialize() { }
    public void Load() { }
}
vb
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.

xaml
<TextBlock x:Name="tb" Text="text"/>
<Button Content="OK" Loaded="{DXEvent Handler='Initialize(@e(tb).Text)'}"/>
csharp
public void Initialize(string arg) { }
vb
Public Sub Initialize(arg As String)
End Sub

To access the event sender and event arguments, use the @sender and @args reserved words.

xaml
<TextBlock x:Name="tb" Text="text"/>
<Button Content="OK" Loaded="{DXEvent Handler='Initialize(@sender.Content, @args, @e(tb).Text)'}"/>
csharp
public void Initialize(object content, RoutedEventArgs args, string text) { }
vb
Public Sub Initialize(content As Object, args As RoutedEventArgs, text As String)
End Sub

The DXEvent extension supports the “ = “ operator.

xaml
<Button Click="{DXEvent '@e(checkBox).IsChecked=true'}"/>

Note

DXEvents cannot be used in EventSetters.