mirror of
https://github.com/soukoku/ntwain.git
synced 2025-09-19 10:08:00 +08:00
Added cap search in wpf sample.
This commit is contained in:
@@ -6,6 +6,7 @@
|
|||||||
Style="{StaticResource AppWindow}">
|
Style="{StaticResource AppWindow}">
|
||||||
<Grid>
|
<Grid>
|
||||||
<Grid.RowDefinitions>
|
<Grid.RowDefinitions>
|
||||||
|
<RowDefinition Height="auto" />
|
||||||
<RowDefinition Height="auto" />
|
<RowDefinition Height="auto" />
|
||||||
<RowDefinition Height="*" />
|
<RowDefinition Height="*" />
|
||||||
</Grid.RowDefinitions>
|
</Grid.RowDefinitions>
|
||||||
@@ -17,7 +18,7 @@
|
|||||||
</Grid.ColumnDefinitions>
|
</Grid.ColumnDefinitions>
|
||||||
|
|
||||||
<Label Content="Sources"></Label>
|
<Label Content="Sources"></Label>
|
||||||
<ListBox x:Name="SrcList" Grid.Row="1" Width="150"
|
<ListBox x:Name="SrcList" Grid.Row="1" Grid.RowSpan="2" Width="150"
|
||||||
SelectionChanged="SrcList_SelectionChanged"
|
SelectionChanged="SrcList_SelectionChanged"
|
||||||
Style="{StaticResource AppListBox}">
|
Style="{StaticResource AppListBox}">
|
||||||
<ListBox.ItemTemplate>
|
<ListBox.ItemTemplate>
|
||||||
@@ -34,7 +35,12 @@
|
|||||||
</ListBox>
|
</ListBox>
|
||||||
|
|
||||||
<Label Content="Caps" Grid.Column="1"></Label>
|
<Label Content="Caps" Grid.Column="1"></Label>
|
||||||
<ListBox x:Name="CapList" Grid.Row="1" Grid.Column="1" Width="150"
|
<TextBox Text="{Binding CapFilter, UpdateSourceTrigger=PropertyChanged}" DataContext="{Binding ElementName=SrcList, Path=SelectedItem}"
|
||||||
|
Grid.Column="1" Grid.Row="1"
|
||||||
|
modern:TextBoxUI.WatermarkText="Find cap name"></TextBox>
|
||||||
|
<ListBox x:Name="CapList" Grid.Row="2" Grid.Column="1" Width="150"
|
||||||
|
DataContext="{Binding ElementName=SrcList, Path=SelectedItem}"
|
||||||
|
ItemsSource="{Binding Caps}"
|
||||||
SelectionChanged="CapList_SelectionChanged"
|
SelectionChanged="CapList_SelectionChanged"
|
||||||
Style="{StaticResource AppListBox}">
|
Style="{StaticResource AppListBox}">
|
||||||
<ListBox.ItemTemplate>
|
<ListBox.ItemTemplate>
|
||||||
@@ -48,7 +54,7 @@
|
|||||||
</ListBox.ItemTemplate></ListBox>
|
</ListBox.ItemTemplate></ListBox>
|
||||||
|
|
||||||
<Label Content="Cap values" Grid.Column="2"></Label>
|
<Label Content="Cap values" Grid.Column="2"></Label>
|
||||||
<ListBox x:Name="CapDetailList" Grid.Row="1" Grid.Column="2" MinWidth="100"
|
<ListBox x:Name="CapDetailList" Grid.Row="1" Grid.RowSpan="2" Grid.Column="2" MinWidth="100"
|
||||||
SelectionChanged="CapDetailList_SelectionChanged"
|
SelectionChanged="CapDetailList_SelectionChanged"
|
||||||
ScrollViewer.CanContentScroll="True"
|
ScrollViewer.CanContentScroll="True"
|
||||||
Style="{StaticResource AppListBox}">
|
Style="{StaticResource AppListBox}">
|
||||||
@@ -64,7 +70,7 @@
|
|||||||
<TextBlock Text="{Binding State}"></TextBlock>
|
<TextBlock Text="{Binding State}"></TextBlock>
|
||||||
<Button Content="Test acquire" Click="Button_Click_1" Margin="4 0"></Button>
|
<Button Content="Test acquire" Click="Button_Click_1" Margin="4 0"></Button>
|
||||||
</StackPanel>
|
</StackPanel>
|
||||||
<modern:AnimatedScrollViewer Grid.Row="1" Grid.Column="3" VerticalScrollBarVisibility="Auto"
|
<modern:AnimatedScrollViewer Grid.Row="1" Grid.RowSpan="2" Grid.Column="3" VerticalScrollBarVisibility="Auto"
|
||||||
HorizontalScrollBarVisibility="Auto">
|
HorizontalScrollBarVisibility="Auto">
|
||||||
<Image Stretch="Uniform" MaxWidth="1000"
|
<Image Stretch="Uniform" MaxWidth="1000"
|
||||||
RenderOptions.BitmapScalingMode="HighQuality"
|
RenderOptions.BitmapScalingMode="HighQuality"
|
||||||
|
@@ -99,17 +99,7 @@ namespace Tester.WPF
|
|||||||
var dsId = SrcList.SelectedItem as DSVM;
|
var dsId = SrcList.SelectedItem as DSVM;
|
||||||
if (dsId != null)
|
if (dsId != null)
|
||||||
{
|
{
|
||||||
var rc = dsId.DS.Open();
|
dsId.Open();
|
||||||
//rc = DGControl.Status.Get(dsId, ref stat);
|
|
||||||
if (rc == ReturnCode.Success)
|
|
||||||
{
|
|
||||||
var caps = dsId.DS.SupportedCaps.Select(o => new CapVM(dsId, o)).OrderBy(o => o.Name).ToList();
|
|
||||||
CapList.ItemsSource = caps;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
CapList.ItemsSource = null;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -17,17 +17,17 @@ namespace Tester.WPF
|
|||||||
MethodInfo _getCurrentMethod;
|
MethodInfo _getCurrentMethod;
|
||||||
MethodInfo _setMethod;
|
MethodInfo _setMethod;
|
||||||
|
|
||||||
public CapVM(DSVM ds, CapabilityId cap)
|
public CapVM(DataSource ds, CapabilityId cap)
|
||||||
{
|
{
|
||||||
_ds = ds.DS;
|
_ds = ds;
|
||||||
Cap = cap;
|
Cap = cap;
|
||||||
Supports = ds.DS.CapQuerySupport(cap);
|
Supports = ds.CapQuerySupport(cap);
|
||||||
|
|
||||||
var capName = cap.ToString();
|
var capName = cap.ToString();
|
||||||
var wrapProperty = ds.DS.GetType().GetProperty(capName);
|
var wrapProperty = ds.GetType().GetProperty(capName);
|
||||||
if (wrapProperty != null)
|
if (wrapProperty != null)
|
||||||
{
|
{
|
||||||
_wrapper = wrapProperty.GetGetMethod().Invoke(ds.DS, null);
|
_wrapper = wrapProperty.GetGetMethod().Invoke(ds, null);
|
||||||
var wrapperType = _wrapper.GetType();
|
var wrapperType = _wrapper.GetType();
|
||||||
_getMethod = wrapperType.GetMethod("Get");
|
_getMethod = wrapperType.GetMethod("Get");
|
||||||
_getCurrentMethod = wrapperType.GetMethod("GetCurrent");
|
_getCurrentMethod = wrapperType.GetMethod("GetCurrent");
|
||||||
|
@@ -1,17 +1,73 @@
|
|||||||
using NTwain;
|
using GalaSoft.MvvmLight;
|
||||||
|
using NTwain;
|
||||||
using NTwain.Data;
|
using NTwain.Data;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Collections.ObjectModel;
|
||||||
|
using System.ComponentModel;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Windows.Data;
|
||||||
|
|
||||||
namespace Tester.WPF
|
namespace Tester.WPF
|
||||||
{
|
{
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Wraps a data source as view model.
|
/// Wraps a data source as view model.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
class DSVM
|
class DSVM : ViewModelBase
|
||||||
{
|
{
|
||||||
public DataSource DS { get; set; }
|
public DataSource DS { get; set; }
|
||||||
|
|
||||||
public string Name { get { return DS.Name; } }
|
public string Name { get { return DS.Name; } }
|
||||||
public string Version { get { return DS.Version.Info; } }
|
public string Version { get { return DS.Version.Info; } }
|
||||||
public string Protocol { get { return DS.ProtocolVersion.ToString(); } }
|
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; }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user