Cleaned up wpf sample with some view models.

This commit is contained in:
soukoku 2014-04-08 07:36:28 -04:00
parent ae03e1df90
commit ec19eb0151
8 changed files with 378 additions and 263 deletions

Binary file not shown.

View File

@ -14,6 +14,24 @@
<ResourceDictionary>
<Style x:Key="AppWindow" TargetType="Window" BasedOn="{StaticResource ModernWindow}"/>
<Style x:Key="AppListBoxItem" TargetType="ListBoxItem" BasedOn="{StaticResource ModernListBoxItem}">
<Setter Property="BorderThickness" Value="1"/>
<Style.Triggers>
<Trigger Property="IsMouseOver" Value="True">
<Setter Property="Background" Value="{DynamicResource ModernBackground2}"/>
</Trigger>
<Trigger Property="IsSelected" Value="True">
<Setter Property="Background" Value="{DynamicResource ModernBackground2}"/>
<Setter Property="Foreground" Value="{DynamicResource ModernForeground}"/>
<Setter Property="BorderBrush" Value="{DynamicResource ModernAccent}"/>
</Trigger>
</Style.Triggers>
</Style>
<Style x:Key="AppListBox" TargetType="ListBox" BasedOn="{StaticResource ModernListBox}">
<Setter Property="ItemContainerStyle" Value="{StaticResource AppListBoxItem}"/>
<Setter Property="BorderThickness" Value="0 1 1 0"/>
<Setter Property="ScrollViewer.CanContentScroll" Value="False"/>
</Style>
</ResourceDictionary>
</ResourceDictionary.MergedDictionaries>
</ResourceDictionary>

33
Tests/Tester.WPF/CapVM.cs Normal file
View File

@ -0,0 +1,33 @@
using NTwain.Values;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace Tester.WPF
{
/// <summary>
/// Wraps a capability as a view model.
/// </summary>
class CapVM
{
public CapabilityId Cap { get; set; }
public string Name
{
get
{
if (Cap > CapabilityId.CustomBase)
{
return "[Custom] " + ((int)Cap - (int)CapabilityId.CustomBase);
}
return Cap.ToString();
}
}
public override string ToString()
{
return Name;
}
}
}

20
Tests/Tester.WPF/DSVM.cs Normal file
View File

@ -0,0 +1,20 @@
using NTwain.Data;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace Tester.WPF
{
/// <summary>
/// Wraps a data source as view model.
/// </summary>
class DSVM
{
public TWIdentity DS { get; set; }
public string Name { get { return DS.ProductName; } }
public string Version { get { return DS.Version.Info; } }
public string Protocol { get { return string.Format("{0}.{1}", DS.ProtocolMajor, DS.ProtocolMinor); } }
}
}

View File

@ -2,7 +2,8 @@
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:modern="http://modernwpf"
Title="TWAIN Tester" Height="600" Width="900" ResizeMode="CanResizeWithGrip"
Title="TWAIN DS Tester" Height="600" Width="900" ResizeMode="CanResizeWithGrip"
modern:Chrome.ShowCaptionIcon="False"
Style="{StaticResource AppWindow}">
<Grid>
<Grid.RowDefinitions>
@ -17,22 +18,29 @@
</Grid.ColumnDefinitions>
<Label Content="Sources"></Label>
<ListBox x:Name="SrcList" Grid.Row="1" BorderThickness="0 1 1 0" ScrollViewer.CanContentScroll="False" Width="150"
SelectionChanged="SrcList_SelectionChanged">
<ListBox x:Name="SrcList" Grid.Row="1" Width="150"
SelectionChanged="SrcList_SelectionChanged"
Style="{StaticResource AppListBox}">
<ListBox.ItemTemplate>
<DataTemplate>
<TextBlock Text="{Binding ProductName}" TextWrapping="Wrap"></TextBlock>
<StackPanel>
<TextBlock Text="{Binding Name}" TextWrapping="Wrap"></TextBlock>
<TextBlock Text="{Binding Version, StringFormat='Version {0}'}" TextWrapping="Wrap" Foreground="{DynamicResource ModernForeground2}"/>
<TextBlock Text="{Binding Protocol, StringFormat='TWAIN {0}'}" Foreground="{DynamicResource ModernForeground2}"/>
</StackPanel>
</DataTemplate>
</ListBox.ItemTemplate>
</ListBox>
<Label Content="Caps" Grid.Column="1"></Label>
<ListBox x:Name="CapList" Grid.Row="1" Grid.Column="1" BorderThickness="0 1 1 0" ScrollViewer.CanContentScroll="False" MinWidth="100"
SelectionChanged="CapList_SelectionChanged"></ListBox>
<ListBox x:Name="CapList" Grid.Row="1" Grid.Column="1" MinWidth="100"
SelectionChanged="CapList_SelectionChanged"
Style="{StaticResource AppListBox}"></ListBox>
<Label Content="Cap values" Grid.Column="2"></Label>
<ListBox x:Name="CapDetailList" Grid.Row="1" Grid.Column="2" BorderThickness="0 1 1 0" ScrollViewer.CanContentScroll="False" MinWidth="100"
SelectionChanged="CapDetailList_SelectionChanged"></ListBox>
<ListBox x:Name="CapDetailList" Grid.Row="1" Grid.Column="2" MinWidth="100"
SelectionChanged="CapDetailList_SelectionChanged"
Style="{StaticResource AppListBox}"></ListBox>
<StackPanel Orientation="Horizontal" Grid.Column="3" >
<Label Content="State:"></Label>
@ -41,8 +49,9 @@
</StackPanel>
<modern:AnimatedScrollViewer Grid.Row="1" Grid.Column="3" VerticalScrollBarVisibility="Auto"
HorizontalScrollBarVisibility="Auto">
<Image x:Name="ImageDisplay" Stretch="Uniform" MaxWidth="1000"
RenderOptions.BitmapScalingMode="HighQuality"></Image>
<Image Stretch="Uniform" MaxWidth="1000"
RenderOptions.BitmapScalingMode="HighQuality"
Source="{Binding Image}"></Image>
</modern:AnimatedScrollViewer>
</Grid>
</Window>

View File

@ -28,7 +28,8 @@ namespace Tester.WPF
/// </summary>
public partial class MainWindow : Window
{
TwainSessionWPF twain;
TwainVM _twainVM;
public MainWindow()
{
InitializeComponent();
@ -41,14 +42,19 @@ namespace Tester.WPF
Title = Title + " (32bit)";
}
SetupTwain();
_twainVM = new TwainVM();
_twainVM.SourceDisabled += delegate
{
ModernMessageBox.Show(this, "Success!");
};
this.DataContext = _twainVM;
}
protected override void OnClosed(EventArgs e)
{
if (twain.State == 4)
if (_twainVM.State == 4)
{
twain.CloseSource();
_twainVM.CloseSource();
}
base.OnClosed(e);
}
@ -58,89 +64,38 @@ namespace Tester.WPF
base.OnSourceInitialized(e);
var hwnd = new WindowInteropHelper(this).Handle;
HwndSource.FromHwnd(hwnd).AddHook(twain.PreFilterMessage);
var rc = twain.OpenManager(hwnd);
// this line is unnecessary if using twain 2 dsm but doesn't hurt to use it
HwndSource.FromHwnd(hwnd).AddHook(_twainVM.PreFilterMessage);
var rc = _twainVM.OpenManager(hwnd);
if (rc == ReturnCode.Success)
{
SrcList.ItemsSource = twain.GetSources();
SrcList.ItemsSource = _twainVM.GetSources().Select(s => new DSVM { DS = s });
}
}
private void SetupTwain()
{
TWIdentity appId = TWIdentity.CreateFromAssembly(DataGroups.Image, Assembly.GetEntryAssembly());
twain = new TwainSessionWPF(appId);
twain.DataTransferred += (s, e) =>
{
if (e.Data != IntPtr.Zero)
{
ImageDisplay.Source = e.Data.GetWPFBitmap();
}
else if (!string.IsNullOrEmpty(e.FilePath))
{
var img = new BitmapImage(new Uri(e.FilePath));
ImageDisplay.Source = img;
}
};
twain.SourceDisabled += delegate
{
ModernMessageBox.Show(this, "Success!");
};
twain.TransferReady += (s, te) =>
{
if (twain.GetCurrentCap<XferMech>(CapabilityId.ICapXferMech) == XferMech.File)
{
var formats = twain.CapGetImageFileFormat();
var wantFormat = formats.Contains(FileFormat.Tiff) ? FileFormat.Tiff : FileFormat.Bmp;
var fileSetup = new TWSetupFileXfer
{
Format = wantFormat,
FileName = System.IO.Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.Desktop), "test.tif")
};
var rc = twain.DGControl.SetupFileXfer.Set(fileSetup);
}
};
this.DataContext = twain;
}
private void Button_Click_1(object sender, RoutedEventArgs e)
{
if (twain.State == 4)
{
if (twain.CapGetPixelTypes().Contains(PixelType.BlackWhite))
{
twain.CapSetPixelType(PixelType.BlackWhite);
}
if (twain.CapGetImageXferMechs().Contains(XferMech.File))
{
twain.CapSetImageXferMech(XferMech.File);
}
var rc = twain.EnableSource(SourceEnableMode.NoUI, false, new WindowInteropHelper(this).Handle, SynchronizationContext.Current);
}
_twainVM.TestCapture(new WindowInteropHelper(this).Handle);
}
private void SrcList_SelectionChanged(object sender, SelectionChangedEventArgs e)
{
if (twain.State == 4)
if (_twainVM.State == 4)
{
twain.CloseSource();
_twainVM.CloseSource();
}
var dsId = SrcList.SelectedItem as TWIdentity;
var dsId = SrcList.SelectedItem as DSVM;
if (dsId != null)
{
var rc = twain.OpenSource(dsId.ProductName);
var rc = _twainVM.OpenSource(dsId.Name);
//rc = DGControl.Status.Get(dsId, ref stat);
if (rc == ReturnCode.Success)
{
var caps = twain.SupportedCaps.Select(o => new CapVM
var caps = _twainVM.SupportedCaps.Select(o => new CapVM
{
Id = o
Cap = o
}).OrderBy(o => o.Name).ToList();
CapList.ItemsSource = caps;
}
@ -151,534 +106,515 @@ namespace Tester.WPF
}
}
class CapVM
{
public CapabilityId Id { get; set; }
public string Name
{
get
{
if (Id > CapabilityId.CustomBase)
{
return "[Custom] " + ((int)Id - (int)CapabilityId.CustomBase);
}
return Id.ToString();
}
}
public override string ToString()
{
return Name;
}
}
private void CapList_SelectionChanged(object sender, SelectionChangedEventArgs e)
{
var capVM = CapList.SelectedItem as CapVM;
if (capVM != null)
{
var cap = capVM.Id;
var cap = capVM.Cap;
switch (cap)
{
case CapabilityId.ACapXferMech:
CapDetailList.ItemsSource = twain.GetCapabilityValues<XferMech>(cap, true);
CapDetailList.ItemsSource = _twainVM.GetCapabilityValues<XferMech>(cap, true);
break;
case CapabilityId.CapAlarms:
CapDetailList.ItemsSource = twain.GetCapabilityValues<AlarmType>(cap, true);
CapDetailList.ItemsSource = _twainVM.GetCapabilityValues<AlarmType>(cap, true);
break;
case CapabilityId.CapAlarmVolume:
CapDetailList.ItemsSource = twain.GetCapabilityValues<ushort>(cap, true);
CapDetailList.ItemsSource = _twainVM.GetCapabilityValues<ushort>(cap, true);
break;
//case CapabilityId.CapAuthor:
// CapDetailList.ItemsSource = twain.GetCapabilityValues<AlarmType>(cap, true);
// CapDetailList.ItemsSource = _twainVM.GetCapabilityValues<AlarmType>(cap, true);
// break;
case CapabilityId.CapAutoFeed:
CapDetailList.ItemsSource = twain.GetCapabilityValues<ushort>(cap, true);
CapDetailList.ItemsSource = _twainVM.GetCapabilityValues<ushort>(cap, true);
break;
case CapabilityId.CapAutomaticCapture:
CapDetailList.ItemsSource = twain.GetCapabilityValues<ushort>(cap, true);
CapDetailList.ItemsSource = _twainVM.GetCapabilityValues<ushort>(cap, true);
break;
case CapabilityId.CapAutomaticSenseMedium:
CapDetailList.ItemsSource = twain.GetCapabilityValues<ushort>(cap, true);
CapDetailList.ItemsSource = _twainVM.GetCapabilityValues<ushort>(cap, true);
break;
case CapabilityId.CapAutoScan:
CapDetailList.ItemsSource = twain.GetCapabilityValues<ushort>(cap, true);
CapDetailList.ItemsSource = _twainVM.GetCapabilityValues<ushort>(cap, true);
break;
case CapabilityId.CapBatteryMinutes:
CapDetailList.ItemsSource = twain.GetCapabilityValues<ushort>(cap, true);
CapDetailList.ItemsSource = _twainVM.GetCapabilityValues<ushort>(cap, true);
break;
case CapabilityId.CapBatteryPercentage:
CapDetailList.ItemsSource = twain.GetCapabilityValues<ushort>(cap, true);
CapDetailList.ItemsSource = _twainVM.GetCapabilityValues<ushort>(cap, true);
break;
case CapabilityId.CapCameraEnabled:
CapDetailList.ItemsSource = twain.GetCapabilityValues<ushort>(cap, true);
CapDetailList.ItemsSource = _twainVM.GetCapabilityValues<ushort>(cap, true);
break;
case CapabilityId.CapCameraOrder:
CapDetailList.ItemsSource = twain.GetCapabilityValues<ushort>(cap, true);
CapDetailList.ItemsSource = _twainVM.GetCapabilityValues<ushort>(cap, true);
break;
case CapabilityId.CapCameraPreviewUI:
CapDetailList.ItemsSource = twain.GetCapabilityValues<ushort>(cap, true);
CapDetailList.ItemsSource = _twainVM.GetCapabilityValues<ushort>(cap, true);
break;
case CapabilityId.CapCameraSide:
CapDetailList.ItemsSource = twain.GetCapabilityValues<CameraSide>(cap, true);
CapDetailList.ItemsSource = _twainVM.GetCapabilityValues<CameraSide>(cap, true);
break;
//case CapabilityId.CapCaption:
// CapDetailList.ItemsSource = twain.GetCapabilityValues<ushort>(cap, true);
// CapDetailList.ItemsSource = _twainVM.GetCapabilityValues<ushort>(cap, true);
// break;
case CapabilityId.CapClearBuffers:
CapDetailList.ItemsSource = twain.GetCapabilityValues<ClearBuffer>(cap, true);
CapDetailList.ItemsSource = _twainVM.GetCapabilityValues<ClearBuffer>(cap, true);
break;
case CapabilityId.CapClearPage:
CapDetailList.ItemsSource = twain.GetCapabilityValues<ushort>(cap, true);
CapDetailList.ItemsSource = _twainVM.GetCapabilityValues<ushort>(cap, true);
break;
case CapabilityId.CapCustomDSData:
CapDetailList.ItemsSource = twain.GetCapabilityValues<ushort>(cap, true);
CapDetailList.ItemsSource = _twainVM.GetCapabilityValues<ushort>(cap, true);
break;
//case CapabilityId.CapCustomInterfaceGuid:
// CapDetailList.ItemsSource = twain.GetCapabilityValues<ushort>(cap, true);
// CapDetailList.ItemsSource = _twainVM.GetCapabilityValues<ushort>(cap, true);
// break;
case CapabilityId.CapDeviceEvent:
CapDetailList.ItemsSource = twain.GetCapabilityValues<DeviceEvent>(cap, true);
CapDetailList.ItemsSource = _twainVM.GetCapabilityValues<DeviceEvent>(cap, true);
break;
case CapabilityId.CapDeviceOnline:
CapDetailList.ItemsSource = twain.GetCapabilityValues<ushort>(cap, true);
CapDetailList.ItemsSource = _twainVM.GetCapabilityValues<ushort>(cap, true);
break;
case CapabilityId.CapDeviceTimeDate:
CapDetailList.ItemsSource = twain.GetCapabilityValues<ushort>(cap, true);
CapDetailList.ItemsSource = _twainVM.GetCapabilityValues<ushort>(cap, true);
break;
case CapabilityId.CapDoubleFeedDetection:
CapDetailList.ItemsSource = twain.GetCapabilityValues<DoubleFeedDetection>(cap, true);
CapDetailList.ItemsSource = _twainVM.GetCapabilityValues<DoubleFeedDetection>(cap, true);
break;
case CapabilityId.CapDoubleFeedDetectionLength:
CapDetailList.ItemsSource = twain.GetCapabilityValues<ushort>(cap, true);
CapDetailList.ItemsSource = _twainVM.GetCapabilityValues<ushort>(cap, true);
break;
case CapabilityId.CapDoubleFeedDetectionResponse:
CapDetailList.ItemsSource = twain.GetCapabilityValues<DoubleFeedDetectionResponse>(cap, true);
CapDetailList.ItemsSource = _twainVM.GetCapabilityValues<DoubleFeedDetectionResponse>(cap, true);
break;
case CapabilityId.CapDoubleFeedDetectionSensitivity:
CapDetailList.ItemsSource = twain.GetCapabilityValues<DoubleFeedDetectionSensitivity>(cap, true);
CapDetailList.ItemsSource = _twainVM.GetCapabilityValues<DoubleFeedDetectionSensitivity>(cap, true);
break;
case CapabilityId.CapDuplex:
CapDetailList.ItemsSource = twain.GetCapabilityValues<Duplex>(cap, true);
CapDetailList.ItemsSource = _twainVM.GetCapabilityValues<Duplex>(cap, true);
break;
case CapabilityId.CapDuplexEnabled:
CapDetailList.ItemsSource = twain.GetCapabilityValues<ushort>(cap, true);
CapDetailList.ItemsSource = _twainVM.GetCapabilityValues<ushort>(cap, true);
break;
case CapabilityId.CapEnableDSUIOnly:
CapDetailList.ItemsSource = twain.GetCapabilityValues<ushort>(cap, true);
CapDetailList.ItemsSource = _twainVM.GetCapabilityValues<ushort>(cap, true);
break;
//case CapabilityId.CapEndorser:
// CapDetailList.ItemsSource = twain.GetCapabilityValues<ushort>(cap, true);
// CapDetailList.ItemsSource = _twainVM.GetCapabilityValues<ushort>(cap, true);
// break;
case CapabilityId.CapExtendedCaps:
CapDetailList.ItemsSource = twain.GetCapabilityValues<ushort>(cap, true);
CapDetailList.ItemsSource = _twainVM.GetCapabilityValues<ushort>(cap, true);
break;
case CapabilityId.CapFeederAlignment:
CapDetailList.ItemsSource = twain.GetCapabilityValues<FeederAlignment>(cap, true);
CapDetailList.ItemsSource = _twainVM.GetCapabilityValues<FeederAlignment>(cap, true);
break;
case CapabilityId.CapFeederEnabled:
CapDetailList.ItemsSource = twain.GetCapabilityValues<ushort>(cap, true);
CapDetailList.ItemsSource = _twainVM.GetCapabilityValues<ushort>(cap, true);
break;
case CapabilityId.CapFeederLoaded:
CapDetailList.ItemsSource = twain.GetCapabilityValues<ushort>(cap, true);
CapDetailList.ItemsSource = _twainVM.GetCapabilityValues<ushort>(cap, true);
break;
case CapabilityId.CapFeederOrder:
CapDetailList.ItemsSource = twain.GetCapabilityValues<FeederOrder>(cap, true);
CapDetailList.ItemsSource = _twainVM.GetCapabilityValues<FeederOrder>(cap, true);
break;
case CapabilityId.CapFeederPocket:
CapDetailList.ItemsSource = twain.GetCapabilityValues<FeederPocket>(cap, true);
CapDetailList.ItemsSource = _twainVM.GetCapabilityValues<FeederPocket>(cap, true);
break;
case CapabilityId.CapFeederPrep:
CapDetailList.ItemsSource = twain.GetCapabilityValues<ushort>(cap, true);
CapDetailList.ItemsSource = _twainVM.GetCapabilityValues<ushort>(cap, true);
break;
case CapabilityId.CapFeedPage:
CapDetailList.ItemsSource = twain.GetCapabilityValues<ushort>(cap, true);
CapDetailList.ItemsSource = _twainVM.GetCapabilityValues<ushort>(cap, true);
break;
case CapabilityId.CapIndicators:
CapDetailList.ItemsSource = twain.GetCapabilityValues<ushort>(cap, true);
CapDetailList.ItemsSource = _twainVM.GetCapabilityValues<ushort>(cap, true);
break;
case CapabilityId.CapIndicatorsMode:
CapDetailList.ItemsSource = twain.GetCapabilityValues<IndicatorsMode>(cap, true);
CapDetailList.ItemsSource = _twainVM.GetCapabilityValues<IndicatorsMode>(cap, true);
break;
case CapabilityId.CapJobControl:
CapDetailList.ItemsSource = twain.GetCapabilityValues<JobControl>(cap, true);
CapDetailList.ItemsSource = _twainVM.GetCapabilityValues<JobControl>(cap, true);
break;
case CapabilityId.CapLanguage:
CapDetailList.ItemsSource = twain.GetCapabilityValues<Language>(cap, true);
CapDetailList.ItemsSource = _twainVM.GetCapabilityValues<Language>(cap, true);
break;
case CapabilityId.CapMaxBatchBuffers:
CapDetailList.ItemsSource = twain.GetCapabilityValues<ushort>(cap, true);
CapDetailList.ItemsSource = _twainVM.GetCapabilityValues<ushort>(cap, true);
break;
case CapabilityId.CapMicrEnabled:
CapDetailList.ItemsSource = twain.GetCapabilityValues<ushort>(cap, true);
CapDetailList.ItemsSource = _twainVM.GetCapabilityValues<ushort>(cap, true);
break;
case CapabilityId.CapPaperDetectable:
CapDetailList.ItemsSource = twain.GetCapabilityValues<ushort>(cap, true);
CapDetailList.ItemsSource = _twainVM.GetCapabilityValues<ushort>(cap, true);
break;
case CapabilityId.CapPaperHandling:
CapDetailList.ItemsSource = twain.GetCapabilityValues<PaperHandling>(cap, true);
CapDetailList.ItemsSource = _twainVM.GetCapabilityValues<PaperHandling>(cap, true);
break;
case CapabilityId.CapPowerSaveTime:
CapDetailList.ItemsSource = twain.GetCapabilityValues<ushort>(cap, true);
CapDetailList.ItemsSource = _twainVM.GetCapabilityValues<ushort>(cap, true);
break;
case CapabilityId.CapPowerSupply:
CapDetailList.ItemsSource = twain.GetCapabilityValues<PowerSupply>(cap, true);
CapDetailList.ItemsSource = _twainVM.GetCapabilityValues<PowerSupply>(cap, true);
break;
case CapabilityId.CapPrinter:
CapDetailList.ItemsSource = twain.GetCapabilityValues<Printer>(cap, true);
CapDetailList.ItemsSource = _twainVM.GetCapabilityValues<Printer>(cap, true);
break;
case CapabilityId.CapPrinterCharRotation:
CapDetailList.ItemsSource = twain.GetCapabilityValues<ushort>(cap, true);
CapDetailList.ItemsSource = _twainVM.GetCapabilityValues<ushort>(cap, true);
break;
case CapabilityId.CapPrinterEnabled:
CapDetailList.ItemsSource = twain.GetCapabilityValues<ushort>(cap, true);
CapDetailList.ItemsSource = _twainVM.GetCapabilityValues<ushort>(cap, true);
break;
case CapabilityId.CapPrinterFontStyle:
CapDetailList.ItemsSource = twain.GetCapabilityValues<PrinterFontStyle>(cap, true);
CapDetailList.ItemsSource = _twainVM.GetCapabilityValues<PrinterFontStyle>(cap, true);
break;
case CapabilityId.CapPrinterIndex:
CapDetailList.ItemsSource = twain.GetCapabilityValues<ushort>(cap, true);
CapDetailList.ItemsSource = _twainVM.GetCapabilityValues<ushort>(cap, true);
break;
case CapabilityId.CapPrinterIndexLeadChar:
CapDetailList.ItemsSource = twain.GetCapabilityValues<ushort>(cap, true);
CapDetailList.ItemsSource = _twainVM.GetCapabilityValues<ushort>(cap, true);
break;
case CapabilityId.CapPrinterIndexMaxValue:
CapDetailList.ItemsSource = twain.GetCapabilityValues<ushort>(cap, true);
CapDetailList.ItemsSource = _twainVM.GetCapabilityValues<ushort>(cap, true);
break;
case CapabilityId.CapPrinterIndexNumDigits:
CapDetailList.ItemsSource = twain.GetCapabilityValues<ushort>(cap, true);
CapDetailList.ItemsSource = _twainVM.GetCapabilityValues<ushort>(cap, true);
break;
case CapabilityId.CapPrinterIndexStep:
CapDetailList.ItemsSource = twain.GetCapabilityValues<ushort>(cap, true);
CapDetailList.ItemsSource = _twainVM.GetCapabilityValues<ushort>(cap, true);
break;
case CapabilityId.CapPrinterIndexTrigger:
CapDetailList.ItemsSource = twain.GetCapabilityValues<PrinterIndexTrigger>(cap, true);
CapDetailList.ItemsSource = _twainVM.GetCapabilityValues<PrinterIndexTrigger>(cap, true);
break;
case CapabilityId.CapPrinterMode:
CapDetailList.ItemsSource = twain.GetCapabilityValues<PrinterMode>(cap, true);
CapDetailList.ItemsSource = _twainVM.GetCapabilityValues<PrinterMode>(cap, true);
break;
//case CapabilityId.CapPrinterString:
// CapDetailList.ItemsSource = twain.GetCapabilityValues<ushort>(cap, true);
// CapDetailList.ItemsSource = _twainVM.GetCapabilityValues<ushort>(cap, true);
// break;
//case CapabilityId.CapPrinterStringPreview:
// CapDetailList.ItemsSource = twain.GetCapabilityValues<ushort>(cap, true);
// CapDetailList.ItemsSource = _twainVM.GetCapabilityValues<ushort>(cap, true);
// break;
//case CapabilityId.CapPrinterSuffix:
// CapDetailList.ItemsSource = twain.GetCapabilityValues<ushort>(cap, true);
// CapDetailList.ItemsSource = _twainVM.GetCapabilityValues<ushort>(cap, true);
// break;
case CapabilityId.CapPrinterVerticalOffset:
CapDetailList.ItemsSource = twain.GetCapabilityValues<ushort>(cap, true);
CapDetailList.ItemsSource = _twainVM.GetCapabilityValues<ushort>(cap, true);
break;
case CapabilityId.CapReacquireAllowed:
CapDetailList.ItemsSource = twain.GetCapabilityValues<ushort>(cap, true);
CapDetailList.ItemsSource = _twainVM.GetCapabilityValues<ushort>(cap, true);
break;
case CapabilityId.CapRewindPage:
CapDetailList.ItemsSource = twain.GetCapabilityValues<ushort>(cap, true);
CapDetailList.ItemsSource = _twainVM.GetCapabilityValues<ushort>(cap, true);
break;
case CapabilityId.CapSegmented:
CapDetailList.ItemsSource = twain.GetCapabilityValues<Segmented>(cap, true);
CapDetailList.ItemsSource = _twainVM.GetCapabilityValues<Segmented>(cap, true);
break;
//case CapabilityId.CapSerialNumber:
// CapDetailList.ItemsSource = twain.GetCapabilityValues<ushort>(cap, true);
// CapDetailList.ItemsSource = _twainVM.GetCapabilityValues<ushort>(cap, true);
// break;
//case CapabilityId.CapSupportedCaps:
// CapDetailList.ItemsSource = twain.GetCapabilityValues<ushort>(cap, true);
// CapDetailList.ItemsSource = _twainVM.GetCapabilityValues<ushort>(cap, true);
// break;
case CapabilityId.CapSupportedCapsSegmentUnique:
CapDetailList.ItemsSource = twain.GetCapabilityValues<ushort>(cap, true);
CapDetailList.ItemsSource = _twainVM.GetCapabilityValues<ushort>(cap, true);
break;
case CapabilityId.CapSupportedDATs:
CapDetailList.ItemsSource = twain.GetCapabilityValues<ushort>(cap, true);
CapDetailList.ItemsSource = _twainVM.GetCapabilityValues<ushort>(cap, true);
break;
case CapabilityId.CapThumbnailsEnabled:
CapDetailList.ItemsSource = twain.GetCapabilityValues<ushort>(cap, true);
CapDetailList.ItemsSource = _twainVM.GetCapabilityValues<ushort>(cap, true);
break;
case CapabilityId.CapTimeBeforeFirstCapture:
CapDetailList.ItemsSource = twain.GetCapabilityValues<ushort>(cap, true);
CapDetailList.ItemsSource = _twainVM.GetCapabilityValues<ushort>(cap, true);
break;
case CapabilityId.CapTimeBetweenCaptures:
CapDetailList.ItemsSource = twain.GetCapabilityValues<ushort>(cap, true);
CapDetailList.ItemsSource = _twainVM.GetCapabilityValues<ushort>(cap, true);
break;
case CapabilityId.CapTimeDate:
CapDetailList.ItemsSource = twain.GetCapabilityValues<ushort>(cap, true);
CapDetailList.ItemsSource = _twainVM.GetCapabilityValues<ushort>(cap, true);
break;
case CapabilityId.CapUIControllable:
CapDetailList.ItemsSource = twain.GetCapabilityValues<ushort>(cap, true);
CapDetailList.ItemsSource = _twainVM.GetCapabilityValues<ushort>(cap, true);
break;
case CapabilityId.CapXferCount:
CapDetailList.ItemsSource = twain.GetCapabilityValues<uint>(cap, true); // spec says ushort but who knows
CapDetailList.ItemsSource = _twainVM.GetCapabilityValues<uint>(cap, true); // spec says ushort but who knows
break;
case CapabilityId.CustomBase:
CapDetailList.ItemsSource = twain.GetCapabilityValues<ushort>(cap, true);
CapDetailList.ItemsSource = _twainVM.GetCapabilityValues<ushort>(cap, true);
break;
case CapabilityId.ICapAutoBright:
CapDetailList.ItemsSource = twain.GetCapabilityValues<ushort>(cap, true);
CapDetailList.ItemsSource = _twainVM.GetCapabilityValues<ushort>(cap, true);
break;
case CapabilityId.ICapAutoDiscardBlankPages:
CapDetailList.ItemsSource = twain.GetCapabilityValues<ushort>(cap, true);
CapDetailList.ItemsSource = _twainVM.GetCapabilityValues<ushort>(cap, true);
break;
case CapabilityId.ICapAutomaticBorderDetection:
CapDetailList.ItemsSource = twain.GetCapabilityValues<ushort>(cap, true);
CapDetailList.ItemsSource = _twainVM.GetCapabilityValues<ushort>(cap, true);
break;
case CapabilityId.ICapAutomaticColorEnabled:
CapDetailList.ItemsSource = twain.GetCapabilityValues<ushort>(cap, true);
CapDetailList.ItemsSource = _twainVM.GetCapabilityValues<ushort>(cap, true);
break;
case CapabilityId.ICapAutomaticColorNonColorPixelType:
CapDetailList.ItemsSource = twain.GetCapabilityValues<PixelType>(cap, true);
CapDetailList.ItemsSource = _twainVM.GetCapabilityValues<PixelType>(cap, true);
break;
case CapabilityId.ICapAutomaticCropUsesFrame:
CapDetailList.ItemsSource = twain.GetCapabilityValues<ushort>(cap, true);
CapDetailList.ItemsSource = _twainVM.GetCapabilityValues<ushort>(cap, true);
break;
case CapabilityId.ICapAutomaticDeskew:
CapDetailList.ItemsSource = twain.GetCapabilityValues<ushort>(cap, true);
CapDetailList.ItemsSource = _twainVM.GetCapabilityValues<ushort>(cap, true);
break;
case CapabilityId.ICapAutomaticLengthDetection:
CapDetailList.ItemsSource = twain.GetCapabilityValues<ushort>(cap, true);
CapDetailList.ItemsSource = _twainVM.GetCapabilityValues<ushort>(cap, true);
break;
case CapabilityId.ICapAutomaticRotate:
CapDetailList.ItemsSource = twain.GetCapabilityValues<ushort>(cap, true);
CapDetailList.ItemsSource = _twainVM.GetCapabilityValues<ushort>(cap, true);
break;
case CapabilityId.ICapAutoSize:
CapDetailList.ItemsSource = twain.GetCapabilityValues<ushort>(cap, true);
CapDetailList.ItemsSource = _twainVM.GetCapabilityValues<ushort>(cap, true);
break;
case CapabilityId.ICapBarcodeDetectionEnabled:
CapDetailList.ItemsSource = twain.GetCapabilityValues<ushort>(cap, true);
CapDetailList.ItemsSource = _twainVM.GetCapabilityValues<ushort>(cap, true);
break;
case CapabilityId.ICapBarcodeMaxRetries:
CapDetailList.ItemsSource = twain.GetCapabilityValues<ushort>(cap, true);
CapDetailList.ItemsSource = _twainVM.GetCapabilityValues<ushort>(cap, true);
break;
case CapabilityId.ICapBarcodeMaxSearchPriorities:
CapDetailList.ItemsSource = twain.GetCapabilityValues<ushort>(cap, true);
CapDetailList.ItemsSource = _twainVM.GetCapabilityValues<ushort>(cap, true);
break;
case CapabilityId.ICapBarcodeSearchMode:
CapDetailList.ItemsSource = twain.GetCapabilityValues<ushort>(cap, true);
CapDetailList.ItemsSource = _twainVM.GetCapabilityValues<ushort>(cap, true);
break;
case CapabilityId.ICapBarcodeSearchPriorities:
CapDetailList.ItemsSource = twain.GetCapabilityValues<ushort>(cap, true);
CapDetailList.ItemsSource = _twainVM.GetCapabilityValues<ushort>(cap, true);
break;
case CapabilityId.ICapBarcodeTimeout:
CapDetailList.ItemsSource = twain.GetCapabilityValues<ushort>(cap, true);
CapDetailList.ItemsSource = _twainVM.GetCapabilityValues<ushort>(cap, true);
break;
case CapabilityId.ICapBitDepth:
CapDetailList.ItemsSource = twain.GetCapabilityValues<ushort>(cap, true);
CapDetailList.ItemsSource = _twainVM.GetCapabilityValues<ushort>(cap, true);
break;
case CapabilityId.ICapBitDepthReduction:
CapDetailList.ItemsSource = twain.GetCapabilityValues<BitDepthReduction>(cap, true);
CapDetailList.ItemsSource = _twainVM.GetCapabilityValues<BitDepthReduction>(cap, true);
break;
case CapabilityId.ICapBitOrder:
CapDetailList.ItemsSource = twain.GetCapabilityValues<BitOrder>(cap, true);
CapDetailList.ItemsSource = _twainVM.GetCapabilityValues<BitOrder>(cap, true);
break;
case CapabilityId.ICapBitOrderCodes:
CapDetailList.ItemsSource = twain.GetCapabilityValues<ushort>(cap, true);
CapDetailList.ItemsSource = _twainVM.GetCapabilityValues<ushort>(cap, true);
break;
case CapabilityId.ICapBrightness:
CapDetailList.ItemsSource = twain.GetCapabilityValues<ushort>(cap, true);
CapDetailList.ItemsSource = _twainVM.GetCapabilityValues<ushort>(cap, true);
break;
case CapabilityId.ICapCCITTKFactor:
CapDetailList.ItemsSource = twain.GetCapabilityValues<ushort>(cap, true);
CapDetailList.ItemsSource = _twainVM.GetCapabilityValues<ushort>(cap, true);
break;
case CapabilityId.ICapColorManagementEnabled:
CapDetailList.ItemsSource = twain.GetCapabilityValues<ushort>(cap, true);
CapDetailList.ItemsSource = _twainVM.GetCapabilityValues<ushort>(cap, true);
break;
case CapabilityId.ICapCompression:
CapDetailList.ItemsSource = twain.GetCapabilityValues<Compression>(cap, true);
CapDetailList.ItemsSource = _twainVM.GetCapabilityValues<Compression>(cap, true);
break;
case CapabilityId.ICapContrast:
CapDetailList.ItemsSource = twain.GetCapabilityValues<ushort>(cap, true);
CapDetailList.ItemsSource = _twainVM.GetCapabilityValues<ushort>(cap, true);
break;
case CapabilityId.ICapCustHalftone:
CapDetailList.ItemsSource = twain.GetCapabilityValues<ushort>(cap, true);
CapDetailList.ItemsSource = _twainVM.GetCapabilityValues<ushort>(cap, true);
break;
case CapabilityId.ICapExposureTime:
CapDetailList.ItemsSource = twain.GetCapabilityValues<ushort>(cap, true);
CapDetailList.ItemsSource = _twainVM.GetCapabilityValues<ushort>(cap, true);
break;
case CapabilityId.ICapExtImageInfo:
CapDetailList.ItemsSource = twain.GetCapabilityValues<ushort>(cap, true);
CapDetailList.ItemsSource = _twainVM.GetCapabilityValues<ushort>(cap, true);
break;
case CapabilityId.ICapFeederType:
CapDetailList.ItemsSource = twain.GetCapabilityValues<FeederType>(cap, true);
CapDetailList.ItemsSource = _twainVM.GetCapabilityValues<FeederType>(cap, true);
break;
case CapabilityId.ICapFilmType:
CapDetailList.ItemsSource = twain.GetCapabilityValues<FilmType>(cap, true);
CapDetailList.ItemsSource = _twainVM.GetCapabilityValues<FilmType>(cap, true);
break;
case CapabilityId.ICapFilter:
CapDetailList.ItemsSource = twain.GetCapabilityValues<FilterType>(cap, true);
CapDetailList.ItemsSource = _twainVM.GetCapabilityValues<FilterType>(cap, true);
break;
case CapabilityId.ICapFlashUsed:
CapDetailList.ItemsSource = twain.GetCapabilityValues<ushort>(cap, true);
CapDetailList.ItemsSource = _twainVM.GetCapabilityValues<ushort>(cap, true);
break;
case CapabilityId.ICapFlashUsed2:
CapDetailList.ItemsSource = twain.GetCapabilityValues<ushort>(cap, true);
CapDetailList.ItemsSource = _twainVM.GetCapabilityValues<ushort>(cap, true);
break;
case CapabilityId.ICapFlipRotation:
CapDetailList.ItemsSource = twain.GetCapabilityValues<FlipRotation>(cap, true);
CapDetailList.ItemsSource = _twainVM.GetCapabilityValues<FlipRotation>(cap, true);
break;
//case CapabilityId.ICapFrames:
// CapDetailList.ItemsSource = twain.GetCapabilityValues<TWFrame>(cap, true);
// CapDetailList.ItemsSource = _twainVM.GetCapabilityValues<TWFrame>(cap, true);
// break;
case CapabilityId.ICapGamma:
CapDetailList.ItemsSource = twain.GetCapabilityValues<ushort>(cap, true);
CapDetailList.ItemsSource = _twainVM.GetCapabilityValues<ushort>(cap, true);
break;
case CapabilityId.ICapHalftones:
CapDetailList.ItemsSource = twain.GetCapabilityValues<ushort>(cap, true);
CapDetailList.ItemsSource = _twainVM.GetCapabilityValues<ushort>(cap, true);
break;
case CapabilityId.ICapHighlight:
CapDetailList.ItemsSource = twain.GetCapabilityValues<ushort>(cap, true);
CapDetailList.ItemsSource = _twainVM.GetCapabilityValues<ushort>(cap, true);
break;
case CapabilityId.ICapICCProfile:
CapDetailList.ItemsSource = twain.GetCapabilityValues<IccProfile>(cap, true);
CapDetailList.ItemsSource = _twainVM.GetCapabilityValues<IccProfile>(cap, true);
break;
case CapabilityId.ICapImageDataset:
CapDetailList.ItemsSource = twain.GetCapabilityValues<ushort>(cap, true);
CapDetailList.ItemsSource = _twainVM.GetCapabilityValues<ushort>(cap, true);
break;
case CapabilityId.ICapImageFileFormat:
CapDetailList.ItemsSource = twain.GetCapabilityValues<FileFormat>(cap, true);
CapDetailList.ItemsSource = _twainVM.GetCapabilityValues<FileFormat>(cap, true);
break;
case CapabilityId.ICapImageFilter:
CapDetailList.ItemsSource = twain.GetCapabilityValues<ImageFilter>(cap, true);
CapDetailList.ItemsSource = _twainVM.GetCapabilityValues<ImageFilter>(cap, true);
break;
case CapabilityId.ICapImageMerge:
CapDetailList.ItemsSource = twain.GetCapabilityValues<ImageMerge>(cap, true);
CapDetailList.ItemsSource = _twainVM.GetCapabilityValues<ImageMerge>(cap, true);
break;
case CapabilityId.ICapImageMergeHeightThreshold:
CapDetailList.ItemsSource = twain.GetCapabilityValues<ushort>(cap, true);
CapDetailList.ItemsSource = _twainVM.GetCapabilityValues<ushort>(cap, true);
break;
case CapabilityId.ICapJpegPixelType:
CapDetailList.ItemsSource = twain.GetCapabilityValues<PixelType>(cap, true);
CapDetailList.ItemsSource = _twainVM.GetCapabilityValues<PixelType>(cap, true);
break;
case CapabilityId.ICapJpegQuality:
CapDetailList.ItemsSource = twain.GetCapabilityValues<JpegQuality>(cap, true);
CapDetailList.ItemsSource = _twainVM.GetCapabilityValues<JpegQuality>(cap, true);
break;
case CapabilityId.ICapJpegSubSampling:
CapDetailList.ItemsSource = twain.GetCapabilityValues<JpegSubSampling>(cap, true);
CapDetailList.ItemsSource = _twainVM.GetCapabilityValues<JpegSubSampling>(cap, true);
break;
case CapabilityId.ICapLampState:
CapDetailList.ItemsSource = twain.GetCapabilityValues<ushort>(cap, true);
CapDetailList.ItemsSource = _twainVM.GetCapabilityValues<ushort>(cap, true);
break;
case CapabilityId.ICapLightPath:
CapDetailList.ItemsSource = twain.GetCapabilityValues<LightPath>(cap, true);
CapDetailList.ItemsSource = _twainVM.GetCapabilityValues<LightPath>(cap, true);
break;
case CapabilityId.ICapLightSource:
CapDetailList.ItemsSource = twain.GetCapabilityValues<LightSource>(cap, true);
CapDetailList.ItemsSource = _twainVM.GetCapabilityValues<LightSource>(cap, true);
break;
case CapabilityId.ICapMaxFrames:
CapDetailList.ItemsSource = twain.GetCapabilityValues<ushort>(cap, true);
CapDetailList.ItemsSource = _twainVM.GetCapabilityValues<ushort>(cap, true);
break;
case CapabilityId.ICapMinimumHeight:
CapDetailList.ItemsSource = twain.GetCapabilityValues<uint>(cap, true);
CapDetailList.ItemsSource = _twainVM.GetCapabilityValues<uint>(cap, true);
break;
case CapabilityId.ICapMinimumWidth:
CapDetailList.ItemsSource = twain.GetCapabilityValues<uint>(cap, true);
CapDetailList.ItemsSource = _twainVM.GetCapabilityValues<uint>(cap, true);
break;
case CapabilityId.ICapMirror:
CapDetailList.ItemsSource = twain.GetCapabilityValues<Mirror>(cap, true);
CapDetailList.ItemsSource = _twainVM.GetCapabilityValues<Mirror>(cap, true);
break;
case CapabilityId.ICapNoiseFilter:
CapDetailList.ItemsSource = twain.GetCapabilityValues<NoiseFilter>(cap, true);
CapDetailList.ItemsSource = _twainVM.GetCapabilityValues<NoiseFilter>(cap, true);
break;
case CapabilityId.ICapOrientation:
CapDetailList.ItemsSource = twain.GetCapabilityValues<NTwain.Values.Orientation>(cap, true);
CapDetailList.ItemsSource = _twainVM.GetCapabilityValues<NTwain.Values.Orientation>(cap, true);
break;
case CapabilityId.ICapOverScan:
CapDetailList.ItemsSource = twain.GetCapabilityValues<OverScan>(cap, true);
CapDetailList.ItemsSource = _twainVM.GetCapabilityValues<OverScan>(cap, true);
break;
case CapabilityId.ICapPatchCodeDetectionEnabled:
CapDetailList.ItemsSource = twain.GetCapabilityValues<ushort>(cap, true);
CapDetailList.ItemsSource = _twainVM.GetCapabilityValues<ushort>(cap, true);
break;
case CapabilityId.ICapPatchCodeMaxRetries:
CapDetailList.ItemsSource = twain.GetCapabilityValues<ushort>(cap, true);
CapDetailList.ItemsSource = _twainVM.GetCapabilityValues<ushort>(cap, true);
break;
case CapabilityId.ICapPatchCodeMaxSearchPriorities:
CapDetailList.ItemsSource = twain.GetCapabilityValues<PatchCode>(cap, true);
CapDetailList.ItemsSource = _twainVM.GetCapabilityValues<PatchCode>(cap, true);
break;
case CapabilityId.ICapPatchCodeSearchMode:
CapDetailList.ItemsSource = twain.GetCapabilityValues<ushort>(cap, true);
CapDetailList.ItemsSource = _twainVM.GetCapabilityValues<ushort>(cap, true);
break;
case CapabilityId.ICapPatchCodeSearchPriorities:
CapDetailList.ItemsSource = twain.GetCapabilityValues<ushort>(cap, true);
CapDetailList.ItemsSource = _twainVM.GetCapabilityValues<ushort>(cap, true);
break;
case CapabilityId.ICapPatchCodeTimeout:
CapDetailList.ItemsSource = twain.GetCapabilityValues<ushort>(cap, true);
CapDetailList.ItemsSource = _twainVM.GetCapabilityValues<ushort>(cap, true);
break;
// TODO phys size are twfix32
case CapabilityId.ICapPhysicalHeight:
CapDetailList.ItemsSource = twain.GetCapabilityValues<uint>(cap, true);
CapDetailList.ItemsSource = _twainVM.GetCapabilityValues<uint>(cap, true);
break;
case CapabilityId.ICapPhysicalWidth:
CapDetailList.ItemsSource = twain.GetCapabilityValues<uint>(cap, true);
CapDetailList.ItemsSource = _twainVM.GetCapabilityValues<uint>(cap, true);
break;
case CapabilityId.ICapPixelFlavor:
CapDetailList.ItemsSource = twain.GetCapabilityValues<PixelFlavor>(cap, true);
CapDetailList.ItemsSource = _twainVM.GetCapabilityValues<PixelFlavor>(cap, true);
break;
case CapabilityId.ICapPixelFlavorCodes:
CapDetailList.ItemsSource = twain.GetCapabilityValues<ushort>(cap, true);
CapDetailList.ItemsSource = _twainVM.GetCapabilityValues<ushort>(cap, true);
break;
case CapabilityId.ICapPixelType:
CapDetailList.ItemsSource = twain.GetCapabilityValues<PixelType>(cap, true);
CapDetailList.ItemsSource = _twainVM.GetCapabilityValues<PixelType>(cap, true);
break;
case CapabilityId.ICapPlanarChunky:
CapDetailList.ItemsSource = twain.GetCapabilityValues<PlanarChunky>(cap, true);
CapDetailList.ItemsSource = _twainVM.GetCapabilityValues<PlanarChunky>(cap, true);
break;
case CapabilityId.ICapRotation:
CapDetailList.ItemsSource = twain.GetCapabilityValues<Rotation>(cap, true);
CapDetailList.ItemsSource = _twainVM.GetCapabilityValues<Rotation>(cap, true);
break;
case CapabilityId.ICapShadow:
CapDetailList.ItemsSource = twain.GetCapabilityValues<ushort>(cap, true);
CapDetailList.ItemsSource = _twainVM.GetCapabilityValues<ushort>(cap, true);
break;
case CapabilityId.ICapSupportedBarcodeTypes:
CapDetailList.ItemsSource = twain.GetCapabilityValues<BarcodeType>(cap, true);
CapDetailList.ItemsSource = _twainVM.GetCapabilityValues<BarcodeType>(cap, true);
break;
case CapabilityId.ICapSupportedExtImageInfo:
CapDetailList.ItemsSource = twain.GetCapabilityValues<ExtendedImageInfo>(cap, true);
CapDetailList.ItemsSource = _twainVM.GetCapabilityValues<ExtendedImageInfo>(cap, true);
break;
case CapabilityId.ICapSupportedPatchCodeTypes:
CapDetailList.ItemsSource = twain.GetCapabilityValues<PatchCode>(cap, true);
CapDetailList.ItemsSource = _twainVM.GetCapabilityValues<PatchCode>(cap, true);
break;
case CapabilityId.ICapSupportedSizes:
CapDetailList.ItemsSource = twain.GetCapabilityValues<SupportedSize>(cap, true);
CapDetailList.ItemsSource = _twainVM.GetCapabilityValues<SupportedSize>(cap, true);
break;
case CapabilityId.ICapThreshold:
CapDetailList.ItemsSource = twain.GetCapabilityValues<ushort>(cap, true);
CapDetailList.ItemsSource = _twainVM.GetCapabilityValues<ushort>(cap, true);
break;
case CapabilityId.ICapTiles:
CapDetailList.ItemsSource = twain.GetCapabilityValues<ushort>(cap, true);
CapDetailList.ItemsSource = _twainVM.GetCapabilityValues<ushort>(cap, true);
break;
case CapabilityId.ICapTimeFill:
CapDetailList.ItemsSource = twain.GetCapabilityValues<ushort>(cap, true);
CapDetailList.ItemsSource = _twainVM.GetCapabilityValues<ushort>(cap, true);
break;
case CapabilityId.ICapUndefinedImageSize:
CapDetailList.ItemsSource = twain.GetCapabilityValues<ushort>(cap, true);
CapDetailList.ItemsSource = _twainVM.GetCapabilityValues<ushort>(cap, true);
break;
case CapabilityId.ICapUnits:
CapDetailList.ItemsSource = twain.GetCapabilityValues<Unit>(cap, true);
CapDetailList.ItemsSource = _twainVM.GetCapabilityValues<Unit>(cap, true);
break;
case CapabilityId.ICapXferMech:
CapDetailList.ItemsSource = twain.GetCapabilityValues<XferMech>(cap, true);
CapDetailList.ItemsSource = _twainVM.GetCapabilityValues<XferMech>(cap, true);
break;
case CapabilityId.ICapXNativeResolution:
CapDetailList.ItemsSource = twain.GetCapabilityValues<ushort>(cap, true);
CapDetailList.ItemsSource = _twainVM.GetCapabilityValues<ushort>(cap, true);
break;
case CapabilityId.ICapXResolution:
CapDetailList.ItemsSource = twain.GetCapabilityValues<ushort>(cap, true);
CapDetailList.ItemsSource = _twainVM.GetCapabilityValues<ushort>(cap, true);
break;
case CapabilityId.ICapXScaling:
CapDetailList.ItemsSource = twain.GetCapabilityValues<ushort>(cap, true);
CapDetailList.ItemsSource = _twainVM.GetCapabilityValues<ushort>(cap, true);
break;
case CapabilityId.ICapYNativeResolution:
CapDetailList.ItemsSource = twain.GetCapabilityValues<ushort>(cap, true);
CapDetailList.ItemsSource = _twainVM.GetCapabilityValues<ushort>(cap, true);
break;
case CapabilityId.ICapYResolution:
CapDetailList.ItemsSource = twain.GetCapabilityValues<ushort>(cap, true);
CapDetailList.ItemsSource = _twainVM.GetCapabilityValues<ushort>(cap, true);
break;
case CapabilityId.ICapYScaling:
CapDetailList.ItemsSource = twain.GetCapabilityValues<ushort>(cap, true);
CapDetailList.ItemsSource = _twainVM.GetCapabilityValues<ushort>(cap, true);
break;
case CapabilityId.ICapZoomFactor:
CapDetailList.ItemsSource = twain.GetCapabilityValues<ushort>(cap, true);
CapDetailList.ItemsSource = _twainVM.GetCapabilityValues<ushort>(cap, true);
break;
default:
if (cap > CapabilityId.CustomBase)
{
CapDetailList.ItemsSource = twain.GetCapabilityValues<ushort>(cap, true);
CapDetailList.ItemsSource = _twainVM.GetCapabilityValues<ushort>(cap, true);
}
else
{

View File

@ -68,6 +68,7 @@
<Generator>MSBuild:Compile</Generator>
<SubType>Designer</SubType>
</ApplicationDefinition>
<Compile Include="TwainVM.cs" />
<Page Include="MainWindow.xaml">
<Generator>MSBuild:Compile</Generator>
<SubType>Designer</SubType>
@ -76,6 +77,8 @@
<DependentUpon>App.xaml</DependentUpon>
<SubType>Code</SubType>
</Compile>
<Compile Include="CapVM.cs" />
<Compile Include="DSVM.cs" />
<Compile Include="MainWindow.xaml.cs">
<DependentUpon>MainWindow.xaml</DependentUpon>
<SubType>Code</SubType>

View File

@ -0,0 +1,96 @@
using NTwain;
using NTwain.Data;
using NTwain.Values;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
using System.Text;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using CommonWin32;
using System.Threading;
namespace Tester.WPF
{
/// <summary>
/// Wraps the twain session as a view model for databinding.
/// </summary>
class TwainVM : TwainSessionWPF
{
public TwainVM()
: base(TWIdentity.CreateFromAssembly(DataGroups.Image | DataGroups.Audio, Assembly.GetEntryAssembly()))
{
}
private ImageSource _image;
/// <summary>
/// Gets or sets the captured image.
/// </summary>
/// <value>
/// The image.
/// </value>
public ImageSource Image
{
get { return _image; }
set
{
_image = value;
RaisePropertyChanged("Image");
}
}
protected override void OnTransferReady(TransferReadyEventArgs e)
{
// set it up to use file xfer
if (this.GetCurrentCap<XferMech>(CapabilityId.ICapXferMech) == XferMech.File)
{
var formats = this.CapGetImageFileFormat();
var wantFormat = formats.Contains(FileFormat.Tiff) ? FileFormat.Tiff : FileFormat.Bmp;
var fileSetup = new TWSetupFileXfer
{
Format = wantFormat,
FileName = System.IO.Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.Desktop), "test.tif")
};
var rc = this.DGControl.SetupFileXfer.Set(fileSetup);
}
base.OnTransferReady(e);
}
protected override void OnDataTransferred(DataTransferredEventArgs e)
{
if (e.Data != IntPtr.Zero)
{
Image = e.Data.GetWPFBitmap();
}
else if (!string.IsNullOrEmpty(e.FilePath))
{
var img = new BitmapImage(new Uri(e.FilePath));
Image = img;
}
base.OnDataTransferred(e);
}
public void TestCapture(IntPtr hwnd)
{
if (State == 4)
{
if (this.CapGetPixelTypes().Contains(PixelType.BlackWhite))
{
this.CapSetPixelType(PixelType.BlackWhite);
}
if (this.CapGetImageXferMechs().Contains(XferMech.File))
{
this.CapSetImageXferMech(XferMech.File);
}
var rc = EnableSource(SourceEnableMode.NoUI, false, hwnd, SynchronizationContext.Current);
}
}
}
}