zoukankan      html  css  js  c++  java
  • Set the single datagridcell enable or disable according to another property in the selected row

    This will set the activity of  single cell in datagrid,instead of the  whole column  with same header.

    It toggle  the validity of the single cell in seperated one row.

    <DataGridTextColumn Binding="{Binding Path=Comment}" Header="Comment">
                        <DataGridTextColumn.CellStyle>
                            <Style TargetType="{x:Type DataGridCell}">
                                <Style.Triggers>
                                    <DataTrigger Binding="{Binding IsActive}" Value="True">
                                        <Setter Property="IsEnabled" Value="False"/>
                                    </DataTrigger>
                                </Style.Triggers>
                            </Style>
                        </DataGridTextColumn.CellStyle> 
                    </DataGridTextColumn>
    private bool isActive = true;
            public bool IsActive
            {
                get
                {
                    return isActive;
                }
                set
                {
                    if(value!=isActive)
                    {
                        isActive = value;
                        OnPropertyChanged("IsActive");
                    }
                }
            }

    <DataGridTemplateColumn Header="Edit" Width="Auto"> <DataGridTemplateColumn.CellTemplate> <DataTemplate> <Button Content="UnLock/Lock" Command="{Binding Path=DataContext.EditCmd, RelativeSource= {RelativeSource FindAncestor,AncestorType={x:Type DataGrid}}}"/> </DataTemplate> </DataGridTemplateColumn.CellTemplate> </DataGridTemplateColumn>

    private ICommand editCmd;
            public ICommand EditCmd
            {
                get
                {
                    if(editCmd==null)
                    {
                        editCmd = new DelegateCommand(EditCmdExecuted, EditCmdCanExecute);
                    }
                    return editCmd;
                }
            }
    private void EditCmdExecuted(object obj)
            {
                SelectedOrder.IsActive = !selectedOrder.IsActive;
            }
    <DataGridTemplateColumn Header="Edit" Width="Auto">
                        <DataGridTemplateColumn.CellTemplate>
                            <DataTemplate>
                                <Button  Content="UnLock/Lock" Command="{Binding Path=DataContext.EditCmd, RelativeSource= {RelativeSource FindAncestor,AncestorType={x:Type DataGrid}}}"/>
                            </DataTemplate>
                        </DataGridTemplateColumn.CellTemplate>
                    </DataGridTemplateColumn>
  • 相关阅读:
    Python面向对象高级编程
    Python面向对象编程
    Anaconda的安装
    Python模块
    Python函数式编程
    Python高级特性
    hdu 3065 病毒侵袭持续中 ac自动机
    hdu 2896 病毒侵袭 ac自动机
    poj 3667 Hotel 线段树
    hdu 4322 Candy 费用流
  • 原文地址:https://www.cnblogs.com/Fred1987/p/14050482.html
Copyright © 2011-2022 走看看