Added cap search in wpf sample.

This commit is contained in:
soukoku
2014-11-14 23:09:12 -05:00
parent c35e727cdb
commit 6370d9c38b
4 changed files with 74 additions and 22 deletions

View File

@@ -17,17 +17,17 @@ namespace Tester.WPF
MethodInfo _getCurrentMethod;
MethodInfo _setMethod;
public CapVM(DSVM ds, CapabilityId cap)
public CapVM(DataSource ds, CapabilityId cap)
{
_ds = ds.DS;
_ds = ds;
Cap = cap;
Supports = ds.DS.CapQuerySupport(cap);
Supports = ds.CapQuerySupport(cap);
var capName = cap.ToString();
var wrapProperty = ds.DS.GetType().GetProperty(capName);
var wrapProperty = ds.GetType().GetProperty(capName);
if (wrapProperty != null)
{
_wrapper = wrapProperty.GetGetMethod().Invoke(ds.DS, null);
_wrapper = wrapProperty.GetGetMethod().Invoke(ds, null);
var wrapperType = _wrapper.GetType();
_getMethod = wrapperType.GetMethod("Get");
_getCurrentMethod = wrapperType.GetMethod("GetCurrent");

View File

@@ -1,17 +1,73 @@
using NTwain;
using GalaSoft.MvvmLight;
using NTwain;
using NTwain.Data;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.ComponentModel;
using System.Linq;
using System.Windows.Data;
namespace Tester.WPF
{
/// <summary>
/// Wraps a data source as view model.
/// </summary>
class DSVM
class DSVM : ViewModelBase
{
public DataSource DS { get; set; }
public string Name { get { return DS.Name; } }
public string Version { get { return DS.Version.Info; } }
public string Protocol { get { return DS.ProtocolVersion.ToString(); } }
ICollectionView _capView;
public DSVM()
{
Caps = new ObservableCollection<CapVM>();
_capView = CollectionViewSource.GetDefaultView(Caps);
_capView.SortDescriptions.Add(new System.ComponentModel.SortDescription("Name", System.ComponentModel.ListSortDirection.Ascending));
_capView.Filter = FilterCapRoutine;
}
private bool FilterCapRoutine(object obj)
{
if (!string.IsNullOrWhiteSpace(CapFilter))
{
var vm = obj as CapVM;
if (vm != null)
{
return vm.Name.IndexOf(CapFilter, System.StringComparison.OrdinalIgnoreCase) > -1;
}
}
return true;
}
public void Open()
{
Caps.Clear();
var rc = DS.Open();
//rc = DGControl.Status.Get(dsId, ref stat);
if (rc == ReturnCode.Success)
{
foreach (var c in DS.SupportedCaps.Select(o => new CapVM(DS, o)))
{
Caps.Add(c);
}
}
}
private string _capFilter;
public string CapFilter
{
get { return _capFilter; }
set
{
_capFilter = value;
_capView.Refresh();
}
}
public ObservableCollection<CapVM> Caps { get; private set; }
}
}