TriggerAction : How to bind event of DataTemplate with MVVM in devexpress gridcontrol

TriggerAction : How to bind event of DataTemplate with MVVM in devexpress gridcontrol

Old forum URL: forums.lhotka.net/forums/t/9814.aspx


simon posted on Tuesday, November 30, 2010

below is my code ,  the method "EditItem" can be executed, but the  e.methodparameter is null.

how to get the current row ? 

 

  public void EditItem(object sender, ExecuteEventArgs e)

        {

            try

            {

                this.Model.

 

                  Shell.Instance.ShowView(typeof(View.ProductCategoryView).AssemblyQualifiedName,

                "productCategorySource", new ViewModel.MM.ProductCategoryViewModel(),"Content");

            }

            catch { }

        }

 

<UserControl x:Class="MES.UI.View.MM.ProductCategorysView"

             xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"

             xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"

             xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 

             xmlns:d="http://schemas.microsoft.com/expression/blend/2008" 

             mc:Ignorable="d" 

             d:DesignHeight="305" d:DesignWidth="441" 

             xmlns:my="clr-namespace:MES.UI.ViewModel.MM" Loaded="UserControl_Loaded" 

             xmlns:dxg="http://schemas.devexpress.com/winfx/2008/xaml/grid" 

             xmlns:dxe="http://schemas.devexpress.com/winfx/2008/xaml/editors"

             xmlns:my1="clr-namespace:Csla.Xaml;assembly=Csla.Xaml">

    <UserControl.Resources>

        <CollectionViewSource x:Key="productCategorysViewModelViewSource"  />

        <CollectionViewSource x:Key="productCategorysViewModelModelViewSource" Source="{Binding Path=Model, Source={StaticResource productCategorysViewModelViewSource}}" />

 

        <DataTemplate x:Key="IdTemplate">

            <StackPanel Orientation="Horizontal" >

                <StackPanel >

                    <Button Name="EditItemButton" Content="{Binding Path=Value}"  Margin="3" Width="100" >

                    </Button>

                 </StackPanel>

 

                <StackPanel Grid.Row="1" DataContext="{Binding Path=CurrentItem,Source={StaticResource productCategorysViewModelViewSource}}">

 

                    <my1:TriggerAction Name="EditItemTrigger1" TargetControl="{Binding ElementName=EditItemButton}" MethodName="EditItem" MethodParameter="{Binding Path=View.FocusedRow, ElementName=gridControl1}" />

                </StackPanel>

            </StackPanel>

        </DataTemplate>

 

    </UserControl.Resources>

    <Grid DataContext="{Binding Source={StaticResource productCategorysViewModelViewSource}}">

        <Grid.RowDefinitions>

            <RowDefinition Height="*" />

            <RowDefinition Height="Auto" />

        </Grid.RowDefinitions>

        <dxg:GridControl Name="gridControl1" DataSource="{Binding Path=Model}" >

            <dxg:GridControl.Columns>

                <dxg:GridColumn FieldName="Id" CellTemplate="{DynamicResource IdTemplate}" Header="Id" SortIndex="0" SortOrder="Ascending"/>

                <dxg:GridColumn FieldName="Name" Header="名称" />

                <dxg:GridColumn FieldName="Description" Header="描述" />

            </dxg:GridControl.Columns>

            <dxg:GridControl.View >

                <dxg:TableView Name="View"  AllowEditing="False"  AutoWidth="True" />

            </dxg:GridControl.View>

 

        </dxg:GridControl>

        <StackPanel Grid.Row="1" DataContext="{Binding Path=CurrentItem,Source={StaticResource productCategorysViewModelViewSource}}">

            <Button Content="Remove" Height="23" Name="Edit1" Width="75" Margin="5" Padding="3" />

            <my1:TriggerAction Name="EditItemTrigger" TargetControl="{Binding ElementName=Edit1}" MethodName="EditItem" MethodParameter="{Binding Path=View.FocusedRow, ElementName=gridControl1}"  />

        </StackPanel>

    </Grid>

</UserControl>

Copyright (c) Marimer LLC