#region Member Fields
// 원본 ItemSource
private ObservableCollection<FileTypeModel> _fileTypeList = new ObservableCollection<FileTypeModel>();
private ICollectionView _internalFileTypeList;
private ICollectionView _internalAcceptFileTypeList;
#endregion // Member Fields
#region Construct
public TransferPolicyViewModel()
{
// For Test
// 가라 데이터
FileTypeModel fileType1 = new FileTypeModel()
{
FileType = "exe",
Description = "설명1",
UseInternal = true
};
FileTypeModel fileType2 = new FileTypeModel()
{
FileType = "jpg",
Description = "설명2",
UseExternal = true
};
FileTypeModel fileType3 = new FileTypeModel()
{
FileType = "gif",
Description = "설명3",
UseInternal = true,
UseExternal = true
};
// 모든 파일 유형 List
FileTypeList.Add(fileType1);
FileTypeList.Add(fileType2);
FileTypeList.Add(fileType3);
// For Test End
InternalFileTypeList = this.GetFileTypeListByInternalFilter(FileTypeList, false);
InternalAcceptFileTypeList = this.GetFileTypeListByInternalFilter(FileTypeList, true);
}
#endregion // // Construct
#region Properties
public ObservableCollection<FileTypeModel> FileTypeList
{
get
{
return _fileTypeList;
}
set
{
_fileTypeList = value;
this.OnPropertyChanged("FileTypeList");
}
}
public ICollectionView InternalFileTypeList
{
get
{
return _internalFileTypeList;
}
set
{
_internalFileTypeList = value;
this.OnPropertyChanged("InternalFileTypeList");
}
}
public ICollectionView InternalAcceptFileTypeList
{
get
{
return _internalAcceptFileTypeList;
}
set
{
_internalAcceptFileTypeList = value;
this.OnPropertyChanged("InternalAcceptFileTypeList");
}
}
#endregion // Properties
#region Methods
private ICollectionView GetFileTypeListByInternalFilter(ObservableCollection<FileTypeModel> source, bool isUse)
{
CollectionViewSource cvs = new CollectionViewSource();
cvs.Source = source;
if (cvs.View.CanFilter)
{
cvs.View.Filter = ((p) =>
{
FileTypeModel fileType = p as FileTypeModel;
if(fileType.UseInternal == isUse)
{
return true;
}
else
{
return false;
}
});
}
return cvs.View;
}
private ICollectionView GetFileTypeListByExternalFilter(ObservableCollection<FileTypeModel> source, bool isUse)
{
CollectionViewSource cvs = new CollectionViewSource();
cvs.Source = source;
if (cvs.View.CanFilter)
{
cvs.View.Filter = ((p) =>
{
FileTypeModel fileType = p as FileTypeModel;
if(fileType.UseExternal == isUse)
{
return true;
}
else
{
return false;
}
});
}
return cvs.View;
}
#endregion // Methods