I want a button to be disabled or enabled based on whether or not a user checks a checkbox on a row in my grid. I can caption the datarecord -- but how do I actually get the button out of the datarecord so that I can disable the button?
This also works for me -- I actually capture the button event -- I did not tell you but I have a xamchk button in the grid so here's how I ended up doing it.
DataRecord dr = ((XamCheckEditor)sender).DataContext as DataRecord; DataRecordPresenter drp = DataRecordPresenter.FromRecord(dr.Cells["BuyOutEditButton"].Record) as DataRecordPresenter; Button b = Infragistics.Windows.Utilities.GetDescendantFromName(drp, "cmdEditBuyout") as Button; b.IsEnabled = (bool)((XamCheckEditor)sender).Value;
THANK YOU!!!!
The procedural code for this should look something like:
On Cell Updated Event
check if the cell is the the one with the checkbox,
then:
DataRecordPresenter drp = DataRecordPresenter.FromRecord(e.Cell.Record) as DataRecordPresenter;
if ((bool)e.Cell.Value == false)
{
Button b = Utilities.GetDescendantFromName(drp, "cmdEditBuyout") as Button;
b.IsEnabled = false;
}
Well,
I read again the initial post, and I see that you want to change the IsEnabled property of the Button according to a checkbox from another field. This can be done in the xaml, without any procedural code. You can try this:
<Style TargetType="{x:Type igDP:CellValuePresenter}" x:Key="b">
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="{x:Type igDP:CellValuePresenter}">
<Button Name="cmdEditBuyout"
Background="{TemplateBinding Background}"
MaxWidth="20" Content="ED"/>
</ControlTemplate>
</Setter.Value>
</Setter>
<Style.Triggers>
<DataTrigger Binding="{Binding Path=Cells[0].Value}" Value="False">
<Setter Property="IsEnabled" Value="False"/>
</DataTrigger>
</Style.Triggers>
</Style>
I am also attaching the sample project for this.
Hope this helps.
I tried to get the parent of the checkbox so I could look for the child button, but this did not work. Any ideas?
DependencyObject parent = Infragistics.Windows.Utilities.GetAncestorFromType(((XamCheckEditor)sender), ((XamCheckEditor)sender).Parent.GetType(), false);
Thanks -- I would have never figured this out. I don't suppose you ahve any exampels of how to call this...