I am trying to associate a list of user data objects with a data network and perform the following behavior.
- Mesh filling
- Disable specific cells based on object data.
Consider the following DataGrid
<DataGrid ItemsSource="{Binding Path=CustomObjectList}">
<DataGrid.Columns>
<DataGridTextColumn Binding="{Binding Path=FieldName}"
Header="Field Name"
IsReadOnly="True" />
<DataGridCheckBoxColumn Binding="{Binding Path=Compare}"
Header="Compare" />
<DataGridTextColumn Binding="{Binding Path=Tolerance}"
Header="Tolerance" />
</DataGrid.Columns>
</DataGrid>
With a support object like this ...
public class CustomObject: BaseModel
{
private bool _compare;
private bool _disableTolerance;
private string _fieldName;
private bool _mustCompare;
private double _tolerance;
public bool Compare
{
get
{
return this._compare;
}
set
{
this._compare = value;
this.NotifyPropertyChange("Compare");
}
}
public bool DisableTolerance
{
get
{
return this._disableTolerance;
}
set
{
this._disableTolerance = value;
this.NotifyPropertyChange("DisableTolerance");
}
}
public string FieldName
{
get
{
return this._fieldName;
}
set
{
this._fieldName = value;
this.NotifyPropertyChange("FieldName");
}
}
public bool MustCompare
{
get
{
return this._mustCompare;
}
set
{
this._mustCompare = value;
this.NotifyPropertyChange("MustCompare");
}
}
public double Tolerance
{
get
{
return this._tolerance;
}
set
{
this._tolerance = value;
this.NotifyPropertyChange("Tolerance");
}
}
}
And you can consider CustomObjectList populated this way ...
this.ComparisonsAndTolerances.Add(new ComparisonSettingsTolerances()
{
FieldName = "Alpha",
Compare = true,
MustCompare = true,
Tolerance = 0,
DisableTolerance = false
});
this.ComparisonsAndTolerances.Add(new ComparisonSettingsTolerances()
{
FieldName = "Bravo",
Compare = true,
MustCompare = false,
Tolerance = 0,
DisableTolerance = true
});
So, of course, the FieldName, Compare, and Tolerance properties are correctly populated in the grid.
However, what I would like to achieve when MustCompare is true is that this cell is marked as read-only. And when DisableTolerance is true, this cell is marked as read-only.
Obviously, this will vary from cell to cell and row to row with 4 different combinations, but I was hoping to achieve this by binding.
I tried
IsReadOnly="{Binding Path=MustCompare}"
and
IsReadOnly="{Binding Path=CustomObjectList/MustCompare}"
But not one of them worked.
.