Radical Documentation
View on GitHub
Primary version
Primary version
  • Home
  • Presentation
    • AbstractViewModel
    • Conventions
      • Bootstrap Conventions
      • Runtime Conventions
      • Conventions override
    • Commands and DelegateCommand
    • IViewResolver
      • Default view behaviors
      • view life cycle events
        • Callback expectations
        • notify messages
    • Message broker MVVM built-in messages
    • Application boot process
      • Application configuration
      • Application shutdown
      • Singleton applications
    • AbstractMementoViewModel
      • Simple ViewModel graphs
      • Collections and complex ViewModel graphs
    • Validation and Validation Services
    • Resources
      • Services as resources
      • ViewModels as resources
  • UI Composition
    • UI Composition
      • Region content lifecycle
      • TabControl region
      • Create a custom region
  • Concepts
    • Inversion of Control
      • Third party DI containers
    • Entities
      • Property System
    • Messaging and Message Broker
      • POCO messages
      • Standalone message handlers
    • Observers
      • PropertyObserver
      • MementoObserver
      • BrokerObserver
  • Memento
    • Change Tracking Service
      • MementoEntity and MementoEntityCollection
      • Handling change tracking:
        • Simple model
        • Collections
        • Complex objects graph
      • Atomic operations
      • Change Tracking Service API
      • Property Metadata for the ChangeTrackingService
      • Handling collection sync
      • Property State
  • Behaviors
    • DataGrid Behaviors
    • Password
    • Generic routed event handler to command behavior
    • Overlay adorner
      • Busy status manager
    • TextBox behaviors:
      • Command
      • Auto select
      • DisableUndoManager (.Net 3.5 only)
  • Markup Extensions
    • Editor binding
    • Auto Command binding
  • How to
    • Get the view of a given view model
    • Bi-directional communication between different windows/views
    • Handle the busy status during async/long running operations
    • Implement a customer improvement program
    • Manage focus
    • Create a splash screen
    • Access view model after view is closed
    • Intercept ViewModels before they are used
  • Upgrade guides
    • Radical Presentation 1.x to Radical 2.x for .NET Core
    • Radical 2.0.0 to Radical 2.1.0
Powered by GitBook
On this page
  • Scenario
  • Radical “Handle”
  • Notes:
  1. Behaviors

Generic routed event handler to command behavior

Scenario

Imagine that you need to handle from the ViewModel the SelectedIndexChanged of a WPF TreeView, currently the only way (without using any particular framework) is to build your own behavior to achieve that, or bind, via a style the IsSelected property of the node to a property of the view model, but in this second case the side effect is that to find the selected item you need to visit the whole tree.

Radical “Handle”

<TreeView Margin="5" HorizontalAlignment="Stretch" VerticalAlignment="Stretch" 
                     ItemsSource="{Binding Path=MyListOfElements}">
    <i:Interaction.Behaviors>
        <behaviors:Handle RoutedEvent="TreeView.SelectedItemChanged"
                          WithCommand="{Binding Path=MyAmazingCommand}"
                          PassingIn="$args.NewValue" />
    </i:Interaction.Behaviors>
    <TreeView.ItemTemplate>
        <!-- omitted -->
    </TreeView.ItemTemplate>
</TreeView>

As you can imagine the value of the NewValue property of the event arguments is passed as the command parameter to the command, we currently support as placeholder:

  • $args: the routed event arguments;

  • $this: the WPF element the behavior is attached to;

  • $source: the source of the routed event;

  • $originalSource: the original source of the routed event;

Notes:

  • the event identified by the RoutedEvent property must be a valid WPF RoutedEvent.

  • the bound command identified by the WithCommand property must be a valid ICommand, AutoCommandBinding is not supported.

The behavior is defined in the http://schemas.radicalframework.com/windows/behaviors xml namespace.

PreviousPasswordNextOverlay adorner

Last updated 3 years ago