Intersoft.Client.Framework.Input Namespace : CommandReference Class |
Public Class CommandReference Inherits System.Windows.FrameworkElement
Dim instance As CommandReference
public class CommandReference : System.Windows.FrameworkElement
public ref class CommandReference : public System.Windows.FrameworkElement
ClientUI streamlines the application development using MVVM pattern with commanding pattern which has been extended to work in both platforms. One of the techniques is using CommandReference to map the input binding to a command.
CommandReference is a multi-purpose component that facilitates declarative XAML binding between an InputBinding and a command in a MVVM pattern application. Although it can be used in various MVVM scenarios, one of the most common usage is to bind an InputBinding such as MouseBinding or KeyBinding, to a command that defined in the ViewModel.
The following code example shows a contact list page with tool bar buttons using MVVM pattern that is compatible with Silverlight and WPF.
XAML |
Copy Code
|
---|---|
<Intersoft:UXPage xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:d="http://schemas.microsoft.com/expression/blend/2008" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" mc:Ignorable="d" xmlns:Intersoft="http://intersoft.clientui.com/schemas" xmlns:local="clr-namespace:Contacts_MVVM.ViewModels" x:Class="Contacts_MVVM.Views.ContactsView" d:DesignWidth="640" d:DesignHeight="480" x:Name="contactsViewPage" Title="My Contacts"> <Intersoft:UXPage.Resources> <local:ContactsViewModel x:Key="ContactsViewModelSource" d:IsDataSource="true"/> </Intersoft:UXPage.Resources> <Grid x:Name="LayoutRoot" DataContext="{Binding Source={StaticResource ContactsViewModelSource}}"> <Grid.Resources> <Intersoft:CommandReference x:Key="AddCommand" Command="{Binding AddCommand}"/> <Intersoft:CommandReference x:Key="EditCommand" Command="{Binding EditCommand}"/> <Intersoft:CommandReference x:Key="DeleteCommand" Command="{Binding DeleteCommand}"/> </Grid.Resources> <Intersoft:CommandManager.InputBindings> <Intersoft:InputBindingCollection> <Intersoft:KeyBinding Command="{StaticResource AddCommand}" Gesture="Ctrl+Shift+A"/> <Intersoft:KeyBinding Command="{StaticResource EditCommand}" Gesture="Ctrl+Shift+E"/> <Intersoft:KeyBinding Command="{StaticResource DeleteCommand}" Gesture="Ctrl+Shift+X"/> </Intersoft:InputBindingCollection> </Intersoft:CommandManager.InputBindings> <Intersoft:DockPanel FillChildMode="Custom"> <Intersoft:UXToolBar Intersoft:DockPanel.Dock="Top"> <Intersoft:UXToolGroup> <Intersoft:UXToolBarButton Command="{Binding AddCommand}" Content="Add New Contact" ToolTipService.ToolTip="Add a new contact (Ctrl + Shift + A)"/> <Intersoft:UXSeparator/> <Intersoft:UXToolBarButton Command="{Binding EditCommand}" Content="Edit Contact" ToolTipService.ToolTip="Edit selected contact (Ctrl + Shift + E)" /> <Intersoft:UXToolBarButton Command="{Binding DeleteCommand}" Content="Delete Contact" ToolTipService.ToolTip="Delete selected contact (Ctrl + Shift + X)"/> </Intersoft:UXToolGroup> </Intersoft:UXToolBar> <Intersoft:UXListBox ItemsSource="{Binding Contacts}" ItemTemplate="{StaticResource ContactViewTemplate}" SelectedItem="{Binding Path=SelectedItem, Mode=TwoWay}"/> </Intersoft:DockPanel> </Grid> <Intersoft:UXPage> |
For a complete walkthrough of using commanding with MVVM pattern, see Walkthrough: Use Command Binding and Key Binding with MVVM Pattern.
For more information about unified development model in ClientUI, see Unified Development Model.
System.Object
System.Windows.DependencyObject
System.Windows.UIElement
System.Windows.FrameworkElement
Intersoft.Client.Framework.Input.CommandReference
Target Platforms: Windows 7, Windows Vista SP1 or later, Windows XP SP3, Windows Server 2008 (Server Core not supported), Windows Server 2008 R2 (Server Core supported with SP1 or later), Windows Server 2003 SP2