I've searched and tried many different things and can't find anything that works. I have two columns in a GridView that are CheckBoxes. The rows are of values that can be set to test the device connected.
Column one is saying if the row contains the default value and is bound to the value from the database whether or not it's checked. This can't be changed by the user. I've set the IsEnabled="false".
Column two allows the user to select a custom value other than the default value. I would love to have it so the row with the default value doesn't have this checkbox. Can't figure out how to make it invisible. So I bind the IsEnabled to a bool in the ViewModel that is set in the code behind based on if it's a default value or not before adding it to the ObservableCollection used for the ListView that holds this GridView. Yet the user can still click on this checkbox in the Default Value's row and it will change to show it was checked. I don't want that either.
I remember in WinForms there was a way to make the CheckBox completely ReadOnly but I could still manipulate its checked state in code. I can't seem to do that with WPF. Help!
XAML:
<GridViewColumn x:Name="lsvThresholdDefaultValue" Header="Default" Width="50">
<GridViewColumn.CellTemplate>
<DataTemplate>
<CheckBox x:Name="cbxDefaultValue"
IsChecked="{Binding DefaultValue}"
IsEnabled="False"/>
</DataTemplate>
</GridViewColumn.CellTemplate>
</GridViewColumn>
<GridViewColumn x:Name="lsvThresholdCustomValue" Header="Use This" Width="55">
<GridViewColumn.CellTemplate>
<DataTemplate>
<CheckBox x:Name="cbxUseThis"
IsChecked="{Binding UseThisValue}"
IsHitTestVisible="False"
IsEnabled="{Binding AllowUse}" />
</DataTemplate>
</GridViewColumn.CellTemplate>
</GridViewColumn>
Code Behind:
if (oneThreshold.DefaultValue)
{
oneThreshold.AllowUse = false;
}
else
{
oneThreshold.AllowUse = true;
}
Aucun commentaire:
Enregistrer un commentaire