In Silverlight (but will probably equally apply to wpf) I have a datagrid which has validation and can go into an invalid state. I check this by:
if(grid.IsValid)
{
...
}
I have a checkbox that triggers saving when unchecked, I wish for this checkbox to be disabled, or at least not uncheck if the grid is in an invalid state.
Something like:
BeforeUncheckEvent
{
if(datagridisvalid)
allow;
else
disallow;
}
Binding to the IsEnabled
based on the grids IsValid
would be even better. This does not work:
IsEnabled="{Binding ElementName=grid, Path=IsValid, UpdateSourceTrigger=PropertyChanged}"
UPDATE>>
I have tried binding another checkbox to the grids IsValid and that works, even when the other checkbox is almost identical to the one that does not work.
SOME CODE>>
When I check this :
<CheckBox x:Name="chkAllowManual" Checked="chkAllowManual_Checked" Unchecked="chkAllowManual_Unchecked" Content="Allow Manual" VerticalAlignment="Center" Margin="3,0,7,0" IsEnabled="{Binding ElementName=grdPrices, Path=IsValid}">
</CheckBox>
The grid gets its itemsource set, has some errors after edit then this gets disabled properly (not the original checkbox but the one next to it) :
<CheckBox x:Name="chkAllowManual1" Checked="chkAllowManual_Checked" Unchecked="chkAllowManual_Unchecked" Content="Allow Manual1" VerticalAlignment="Center" Margin="3,0,7,0" IsEnabled="{Binding ElementName=grdPrices, Path=IsValid}">
</CheckBox>
Any ideas?
IsEnabled
binding that you say didn't work? (You can find errors in the Output Window in Visual Studio.) – Sheridan