0

我有以下内容:

public enum ValidationSeverity 
{
    Error   = 1,
    Warning = 2
}

Public class Errors
{
   public ValidationSeverity Severity { set; get; }
   public string Desc { set; get; }
}

在 ViewModel 定义的 ObservableCollection 中,我将它绑定到 sdk 的 DataGrid,现在我有两个切换按钮:

  • 显示错误
  • 显示警告
  • -

当我单击“显示错误”时,数据网格将只有它们的严重性为“错误”的行。我正在尝试使用 ICollectionView,就像我点击“显示错误”时一样,它将转到:

    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 - 我添加了这个,因为在 Silverlight 中我们不能直接使用 GetCollectionView,现在我的问题是我怎么能做到这一点,我写了两个谓词,但是我怎么能继续,如果我编辑 collectionView 是否会导致改变看法?

谢谢

4

1 回答 1

0

The view is just a wrapper around the collection, if you edit the collection the changes will be reflected in the collectionview also, so basically you must edit the ErrorList.

于 2013-09-10T11:52:27.487 回答