I've the following:
public enum ValidationSeverity
{
Error = 1,
Warning = 2
}
Public class Errors
{
public ValidationSeverity Severity { set; get; }
public string Desc { set; get; }
}
in the ViewModel defined ObservableCollection, and I bound it to DataGrid of the sdk, now I've two toggle buttons:
- Show Errors
- Show Warnings -
When I click on "Show Errors", the data grid will just have the rows that the Severity of them is "Error". I'm trying to use ICollectionView, like that when I click on "Show Errors", it will go to:
private void OnShowErrors()
{
if (IsErrorButtonChecked)
Show(ValidationSeverity.Error);
else
Hide(ValidationSeverity.Error);
}
private void Hide(ValidationSeverity sev)
{
var lcv = _collectionViewSourceHelper.GetCollectionView(ErrorsList);
if (lcv == null || !lcv.CanFilter) return;
lcv.Filter = item =>
{
var error = item as Error;
if (error == null) return false;
return error.Severity != sev;
};
}
private void Show(ValidationSeverity sev)
{
var lcv = _collectionViewSourceHelper.GetCollectionView(ErrorsList);
if (lcv == null || !lcv.CanFilter) return;
lcv.Filter = item =>
{
var error = item as Error;
if (error == null) return false;
return error.Severity == sev;
};
}
_collectionViewSourceHelper - I added this, cause in the Silverlight we can't use the GetCollectionView directly, now my question is how I can do that, I wrote two predicates, but how I can continues, if I edit the collectionView does it cause changing the view?
Thanks