• WPF GridControl Command 的时候 传我需要的参数


    如果不使用MVVM。直接调用GridControl 事件 取当前单击某一列的值。

    如果在MVVM中那么则使用Command 。通过Command传递参数等 就比以往的直接调用事件复杂。。

    需求:

    在点击  GridConrol的时候 下面值跟着变化。。主要是通过鼠标 RowDoubleClick 和键盘 Enter 时 调用Command

    MVVM:

    View Code
      <UserControl.Resources>
            <!--数据模板-->
            <DataTemplate x:Key="RowDetailTemplate">
                <GroupBox Grid.Row="3" Header="用户基本信息">
                    <Grid >
                        <Grid.ColumnDefinitions>
                            <ColumnDefinition Width="300*" />
                            <ColumnDefinition Width="300*" />
                        </Grid.ColumnDefinitions>
                        <Grid.RowDefinitions>
                            <RowDefinition Height="37*" />
                            <RowDefinition Height="46*" />
                            <RowDefinition Height="44*" />
                        </Grid.RowDefinitions>
                        <TextBlock Height="23" HorizontalAlignment="Left" Margin="7,8,0,0"  Text="用户编号:" VerticalAlignment="Top" />
                        <TextBlock Grid.Column="1" Height="23" HorizontalAlignment="Left"  Text="用户名称:" VerticalAlignment="Center" />
                        <TextBlock Grid.Row="1" Height="23" HorizontalAlignment="Left" Margin="7,19,0,0"  Text="用户角色:" VerticalAlignment="Top" />
                        <TextBlock Grid.Row="1" Height="23" HorizontalAlignment="Left" Margin="199,18,0,0"  Text="用户性别:" VerticalAlignment="Top" />
                        <TextBlock Grid.Column="1" Grid.Row="1" Height="23" HorizontalAlignment="Left"  Text="用户年龄:" VerticalAlignment="Center" />
                        <!--绑定相关的字段-->
                        <dxe:TextEdit Height="23" Text="{Binding Path=UserCode}" HorizontalAlignment="Left" Margin="64,5,0,0" VerticalAlignment="Top" Width="120" />
                        <dxe:TextEdit Grid.Column="1" Text="{Binding Path=UserName}" Height="23" HorizontalAlignment="Left" Margin="67,6,0,0"  VerticalAlignment="Top" Width="120" />
                        <dxe:TextEdit Grid.Row="1" Height="23" Text="{Binding Path=UserRole}" HorizontalAlignment="Left" Margin="64,19,0,0" VerticalAlignment="Top" Width="120" />
                        <dxe:ComboBoxEdit Grid.Row="1" Text="{Binding Path=UserGender}" Height="23" HorizontalAlignment="Left" Margin="256,18,0,0" Name="comboBox1" VerticalAlignment="Top" Width="65">
                            <dxe:ComboBoxEditItem Content="男" />
                            <dxe:ComboBoxEditItem Content="女" />
                        </dxe:ComboBoxEdit>
                        <dxe:TextEdit Grid.Column="1" Text="{Binding Path=UserAge}" Grid.Row="1" Height="23" HorizontalAlignment="Right" Margin="0,0,207,0"  VerticalAlignment="Center" Width="120" />
                        <Button Content="新增" Grid.Row="2" Grid.ColumnSpan="2" Height="23" HorizontalAlignment="Center" Name="btnSave" Margin="-250,0,0,0" VerticalAlignment="Center" Width="75" />
                        <Button Content="删除" Grid.Row="2"  Grid.ColumnSpan="2" Height="23" HorizontalAlignment="Center" Margin="90,0,0,0"  Name="btnDelete" VerticalAlignment="Center" Width="75" />
                        <Button Content="取消" Grid.Row="2" Grid.ColumnSpan="2" Height="23" HorizontalAlignment="Center"  Name="btnCancel" Margin="260,0,0,0" VerticalAlignment="Center" Width="75" />
                        <Button Content="保存"  Height="23" HorizontalAlignment="Center" Grid.ColumnSpan="2" Margin="-80,0,0,0" Name="button2" VerticalAlignment="Center" Width="75" Grid.Row="2" />
                    </Grid>
                </GroupBox>
            </DataTemplate>
        </UserControl.Resources>
        <Grid >
            <Grid.RowDefinitions>
                <RowDefinition Height="Auto" />
                <RowDefinition Height="Auto" />
                <RowDefinition Height="250*" />
                <RowDefinition Height="Auto" />
            </Grid.RowDefinitions>
            <!--用于显示 标题或导航菜单-->
            <ContentControl Content="{Binding Navigator.View}" HorizontalAlignment="Stretch" HorizontalContentAlignment="Stretch" VerticalAlignment="Stretch" />
            <!--检索-->
            <Border BorderBrush="Silver" BorderThickness="1" Height="51"  Name="border1"  Grid.Row="1">
                <StackPanel Orientation="Horizontal">
                    <Label Content="用户信息:"  VerticalAlignment="Center" HorizontalAlignment="Left" />
                    <dxe:TextEdit Height="23" Name="textBox1" Width="245" VerticalAlignment="Center"/>
                    <Button Content="检索" Margin="20,0,0,0" Height="23" HorizontalAlignment="Left" Command="{Binding SelectButtonCommand}" VerticalAlignment="Center" Width="75" />
                </StackPanel>
            </Border>
            <!--数据列表-->
            <dxg:GridControl  Grid.Row="2" Name="UsersDataGrid" ItemsSource="{Binding Data.Rats}">
                <dxg:GridControl.Columns>
                    <dxg:GridColumn  Header="用户编号" FieldName="UserCode"/>
                    <dxg:GridColumn  Header="用户名称" FieldName="UserName"/>
                    <dxg:GridColumn  Header="用户角色" FieldName="UserRole"/>
                    <dxg:GridColumn  Header="用户姓别" FieldName="UserGender"/>
                    <dxg:GridColumn  Header="用户年龄" FieldName="UserAge" />
                </dxg:GridControl.Columns>
                <dxg:GridControl.View>
                    <dxg:TableView Name="View" AutoWidth="True" AllowPerPixelScrolling="True" ShowGroupPanel="False" AllowFilterEditor="False" ShowGroupedColumns="True"
                            BestFitMode="Smart" BestFitArea="All" ShowHorizontalLines="False" AllowEditing="False" NavigationStyle="Row" AllowHorizontalScrollingVirtualization="False" FadeSelectionOnLostFocus="False"
                            ShowIndicator="False" >
                        <interactivity:Interaction.Triggers>
                            <interactivity:EventTrigger EventName="KeyDown">
                                <helpers:KeyEventAction Key="Enter" Command="{Binding ShowDataGridCommand}" CommandParameter="{Binding ElementName=View,Path=FocusedRow}"/>
                            </interactivity:EventTrigger>
                            <interactivity:EventTrigger EventName="RowDoubleClick">
                                <interactivity:InvokeCommandAction  Command="{ Binding ShowDataGridCommand}" CommandParameter="{Binding ElementName=View, Path=FocusedRow}"/>
                            </interactivity:EventTrigger>
                        </interactivity:Interaction.Triggers>
                        </dxg:TableView>
                </dxg:GridControl.View>
            </dxg:GridControl>
            <!--显示定义的数据模板-->
            <ContentPresenter Grid.Row="3" Content="{Binding Path=View.FocusedRowData.Row, ElementName=UsersDataGrid}" ContentTemplate="{StaticResource RowDetailTemplate}" HorizontalAlignment="Stretch"/>
        </Grid>
    View Model
    public class UserManageView : ModuleWithNavigator
        {
            public UserManageView()
            {
                Title = "用户管理";
            }
    
            #region  Command
    
            private void GridCellClick(object sender)
            {
    
            }
    
            protected override void InitializeCommands()
            {
                ShowDataGridCommand = new SimpleActionCommand(GridCellClick);
                SelectButtonCommand = new SimpleActionCommand(ButtonCommand);
            }
            public ICommand ShowDataGridCommand { get; private set; }
            public ICommand SelectButtonCommand { get; private set; }
            void ButtonCommand(object sender)
            {
                if (sender == null)
                    return;
                string value = sender.ToString();
                switch (value)
                {
                    case "Add":
                        DXMessageBox.Show(value, "Caption", MessageBoxButton.OK, MessageBoxImage.Information);
                        break;
                    case "Edit":
                        DXMessageBox.Show(value, "Caption", MessageBoxButton.OK, MessageBoxImage.Information);
                        break;
                    case "Delete":
                        DXMessageBox.Show(value, "Caption", MessageBoxButton.OK, MessageBoxImage.Information);
                        break;
                    case "Check":
                        DXMessageBox.Show(value, "Caption", MessageBoxButton.OK, MessageBoxImage.Information);
                        break;
                    case "Print":
                        DXMessageBox.Show(value, "Caption", MessageBoxButton.OK, MessageBoxImage.Information);
                        break;
                }
            }
    
            #endregion
        }

    在这里做个备注、、、

  • 相关阅读:
    执行插件的替代方式:用JS调用操作
    查找字段的筛选-使用addCustomView
    Dynamics CRM 中Web API中的深度创建(Deep Insert)
    使用JS通过Web API执行批量操作,多个操作是一个事务!
    使用Dynamics 365 CE Web API查询数据加点料及选项集字段常用查询
    配置Postman通过OAuth 2 implicit grant获取Dynamics 365 CE Online实例的Access Token
    Dynamics 365 Customer Engagement中使用JavaScript和C#调用操作Action示例
    Dynamics 365 We API ODATA语法根据父记录查询子记录,根据子记录查询父记录(附上根据团队,队列名称查成员)
    Dynamics 365 Online通过OAuth 2 Client Credential授权(Server-to-Server Authentication)后调用Web API
    控制台程序(C#)不弹出登录窗口连接到Dynamics CRM Online的Web API
  • 原文地址:https://www.cnblogs.com/w2011/p/2828085.html
Copyright © 2020-2023  润新知