Question

I have a xamnumericeditor in my first column and a button in my 4th column. I want to Enable the button when user edits the xamnumericeditor in first column.

I want to do it from code behind, also i have method call "Cellupdated" which is called as soon as the user edits the cell.

the button is inside a fieldlayout .

Xaml of Fieldslayout

<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>
Was it helpful?

Solution

If you bind a ICommand to your button, you can control the button Enabled property through the CanExecute method. If the method returns true the button turns enabled, otherwise turns disabled.

Prism offers out of the box the DelegateCommand that turns easy the implementation of commands.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top