How would you enable or disable a button in a GridRow based on the row index. I have a number of grids that have a minimum requirement, but the user would be able to delete rows if they are non required records.
I think the problem has to be fixed with setting RelativeSource, but it depends.
Without setting the relative source, this binding will target the DataRecordPresenter and will not be able to find IsCustom there. IsCustom is a property of the underlying object, so you might want to try with the cells collection ( as the code snipper above) or with the DataItem property of the Record of the DataRecordPresenter.
If IsCustom property is displayed in the same cell, as the button, you have to set RelativeSource to Self.
I am attaching the sample project just in case.
FYI, I also tried to bind by cell value. IsCustom values are correct as far as I can tell.
I have spent all morning trying to get these triggers to work... Any idea what I am doing wrong?
<igDataGrid:UnboundField Name="BuyOutEditButton" Label="B/O"> <igDataGrid:UnboundField.Settings> <igDataGrid:FieldSettings LabelWidth="40" CellWidth="40" AllowEdit="True"> <igDataGrid:FieldSettings.CellValuePresenterStyle> <Style TargetType="{x:Type igDataGrid:CellValuePresenter}"> <Setter Property="Template"> <Setter.Value> <ControlTemplate TargetType="{x:Type igDataGrid:CellValuePresenter}"> <Button Name="cmdEditBuyout" MinWidth="20" MinHeight="5" Height="22" Click="cmdEditBuyout_Click" IsEnabled="False" >Edit</Button> </ControlTemplate> </Setter.Value> </Setter> <Style.Triggers> <DataTrigger Binding="{Binding Path=IsCustom}" Value="false"> <Setter Property="IsEnabled" Value="false"/> </DataTrigger> <DataTrigger Binding="{Binding Path=IsCustom}" Value="true"> <Setter Property="IsEnabled" Value="true"/> </DataTrigger> </Style.Triggers> </Style> </igDataGrid:FieldSettings.CellValuePresenterStyle> </igDataGrid:FieldSettings> </igDataGrid:UnboundField.Settings> </igDataGrid:UnboundField>
Here is a sample code snippet that does the trick:
<Style TargetType="{x:Type igDP:CellValuePresenter}" x:Key="buttonCell">
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="{x:Type igDP:CellValuePresenter}">
<Button MaxWidth="20" Content="EDIT"/>
</ControlTemplate>
</Setter.Value>
</Setter>
<Style.Triggers>
<DataTrigger Binding="{Binding Path=Cells[0].Value}" Value="False">
<Setter Property="IsEnabled" Value="False"/>
</DataTrigger>
</Style.Triggers>
</Style>
,where the checkbox is in my first field.
Hope this helps
My question is very similiar:
On my binding I need to enable/disable button on a row based on a checkbox's value on the same row. I don't fully understand what you've said, but I was hoping kind of an on row binding event where I could test this. Right now it happens on the valuechanged event and works correctly. However, on binding it's like that value changed is not called and so I think I have to find a way to do it per row... I guess I could do it on grid_load event and loop through each datarecord but that doesn't seem very eligant.