在XamDatagrid中的fieldlayout内启用按钮

时间:2013-11-28 10:31:21

标签: c# wpf infragistics xamdatagrid

我的第一列中有一个xamnumericeditor,第四列中有一个按钮。我想在用户编辑第一列中的xamnumericeditor时启用该按钮。

我想从后面的代码中做到这一点,我也有方法调用“Cellupdated”,一旦用户编辑单元格就会调用它。

按钮位于fieldlayout内。

Fieldslayout的Xaml

<Style x:Key="buttonInCellStyle" TargetType="{x:Type igDP:CellValuePresenter}">
            <Setter Property="Template">
                <Setter.Value>
                    <ControlTemplate TargetType="{x:Type igDP:CellValuePresenter}">
                        <Button  x:Name="btnRemoveCommands" Click="Button_Click" Width="50" Background="Transparent" BorderThickness="0" BorderBrush="Transparent">
                            <Image  Source="..\Resources\delete.png"  Stretch="UniformToFill"   VerticalAlignment="Center" HorizontalAlignment="Center" Height="16" Width="16"/>
                                <Button.Style>
                                <Style TargetType="{x:Type Button}">
                                    <Style.Triggers>
                                        <DataTrigger Binding="{Binding RelativeSource={RelativeSource Self}, Path=DataContext.DataItem.RemoveCommandsVisibility}"  Value="True">
                                            <Setter Property="Visibility" Value="Visible"/>
                                        </DataTrigger>
                                        <DataTrigger Binding="{Binding RelativeSource={RelativeSource Self}, Path=DataContext.DataItem.RemoveCommandsVisibility}" Value="False">
                                            <Setter Property="Visibility" Value="Hidden"/>
                                        </DataTrigger>
                                        <!--<DataTrigger Binding="{Binding RelativeSource={RelativeSource Self}, Path=DataContext.DataItem.CurrentValueNullable,Mode=TwoWay}"  Value="{x:Null}">
                                            <Setter Property="Visibility" Value="Hidden"/>
                                        </DataTrigger>-->

                                    </Style.Triggers>
                                </Style>
                            </Button.Style>
                        </Button>
                    </ControlTemplate>
                </Setter.Value>
              </Setter>
                   </Style>



private void dtgAdmin_CellUpdated(object sender, Infragistics.Windows.DataPresenter.Events.CellUpdatedEventArgs e)
{

//need to disable the button here

}

  <igDP:FieldLayout>
                    <igDP:FieldLayout.Fields>
                        <igDP:Field Name="Description"   Label="{LocText Key=HeaderParameter, Assembly=Sample}">
                            <igDP:Field.Settings>
                                <igDP:FieldSettings CellMinWidth="100"  CellValuePresenterStyle="{StaticResource NormalCellStyle}" AllowEdit="False" />
                            </igDP:Field.Settings>
                        </igDP:Field>
                        <igDP:Field Name="CurrentValueNullable" Label="{LocText Key=HeaderCurrentValue, Assembly=Sample}">
                            <igDP:Field.Settings>
                                <igDP:FieldSettings EditorStyle="{StaticResource EditCellStyle}" EditorType="{x:Type igEditors:XamNumericEditor}" EditAsType="{x:Type sys:Int16}" CellMinWidth="50"  />
                            </igDP:Field.Settings>
                        </igDP:Field>
                        <igDP:Field Name="MinValueStr"  Label="{LocText Key=HeaderMinValue, Assembly=Sample}">
                            <igDP:Field.Settings>
                                <igDP:FieldSettings CellMinWidth="50" CellValuePresenterStyle="{StaticResource NormalCellStyle}" AllowEdit="False" />
                            </igDP:Field.Settings>
                        </igDP:Field>
                        <igDP:Field Name="MaxValueStr"  Label="{LocText Key=HeaderMaxValue, Assembly=Sample}">
                            <igDP:Field.Settings>
                                <igDP:FieldSettings  Width="50" CellValuePresenterStyle="{StaticResource NormalCellStyle}" AllowEdit="False" />
                            </igDP:Field.Settings>
                        </igDP:Field>

                        <igDP:Field Name="RemoveCommands"  Label="Clear">
                            <igDP:Field.Settings>
                                <igDP:FieldSettings  Width="16" CellValuePresenterStyle="{StaticResource buttonInCellStyle}" />
                            </igDP:Field.Settings>
                        </igDP:Field>

1 个答案:

答案 0 :(得分:1)

如果将ICommand绑定到按钮,则可以通过CanExecute方法控制按钮Enabled属性。如果方法返回true,则按钮变为启用状态,否则将禁用。

Prism提供开箱即用的DelegateCommand,可以轻松实现命令。