├── .gitignore ├── D2dControl.sln ├── D2dControl ├── D2dControl.cs ├── D2dControl.csproj ├── D2dControl.nuspec ├── Disposer.cs ├── Dx11ImageSource.cs ├── NativeMethods.cs ├── Properties │ └── AssemblyInfo.cs ├── ResourceCache.cs ├── app.config └── packages.config ├── LICENSE ├── README.md └── Sample ├── App.config ├── App.xaml ├── App.xaml.cs ├── MainWindow.xaml ├── MainWindow.xaml.cs ├── Properties ├── AssemblyInfo.cs ├── Resources.Designer.cs ├── Resources.resx ├── Settings.Designer.cs └── Settings.settings ├── Sample.csproj ├── SampleControl.cs └── packages.config /.gitignore: -------------------------------------------------------------------------------- 1 | ## Ignore Visual Studio temporary files, build results, and 2 | ## files generated by popular Visual Studio add-ons. 3 | 4 | # User-specific files 5 | *.suo 6 | *.user 7 | *.userosscache 8 | *.sln.docstates 9 | 10 | # User-specific files (MonoDevelop/Xamarin Studio) 11 | *.userprefs 12 | 13 | # Build results 14 | [Dd]ebug/ 15 | [Dd]ebugPublic/ 16 | [Rr]elease/ 17 | [Rr]eleases/ 18 | x64/ 19 | x86/ 20 | build/ 21 | bld/ 22 | [Bb]in/ 23 | [Oo]bj/ 24 | 25 | # Visual Studo 2015 cache/options directory 26 | .vs/ 27 | 28 | # MSTest test Results 29 | [Tt]est[Rr]esult*/ 30 | [Bb]uild[Ll]og.* 31 | 32 | # NUNIT 33 | *.VisualState.xml 34 | TestResult.xml 35 | 36 | # Build Results of an ATL Project 37 | [Dd]ebugPS/ 38 | [Rr]eleasePS/ 39 | dlldata.c 40 | 41 | *_i.c 42 | *_p.c 43 | *_i.h 44 | *.ilk 45 | *.meta 46 | *.obj 47 | *.pch 48 | *.pdb 49 | *.pgc 50 | *.pgd 51 | *.rsp 52 | *.sbr 53 | *.tlb 54 | *.tli 55 | *.tlh 56 | *.tmp 57 | *.tmp_proj 58 | *.log 59 | *.vspscc 60 | *.vssscc 61 | .builds 62 | *.pidb 63 | *.svclog 64 | *.scc 65 | 66 | # Chutzpah Test files 67 | _Chutzpah* 68 | 69 | # Visual C++ cache files 70 | ipch/ 71 | *.aps 72 | *.ncb 73 | *.opensdf 74 | *.sdf 75 | *.cachefile 76 | 77 | # Visual Studio profiler 78 | *.psess 79 | *.vsp 80 | *.vspx 81 | 82 | # TFS 2012 Local Workspace 83 | $tf/ 84 | 85 | # Guidance Automation Toolkit 86 | *.gpState 87 | 88 | # ReSharper is a .NET coding add-in 89 | _ReSharper*/ 90 | *.[Rr]e[Ss]harper 91 | *.DotSettings.user 92 | 93 | # JustCode is a .NET coding addin-in 94 | .JustCode 95 | 96 | # TeamCity is a build add-in 97 | _TeamCity* 98 | 99 | # DotCover is a Code Coverage Tool 100 | *.dotCover 101 | 102 | # NCrunch 103 | _NCrunch_* 104 | .*crunch*.local.xml 105 | 106 | # MightyMoose 107 | *.mm.* 108 | AutoTest.Net/ 109 | 110 | # Web workbench (sass) 111 | .sass-cache/ 112 | 113 | # Installshield output folder 114 | [Ee]xpress/ 115 | 116 | # DocProject is a documentation generator add-in 117 | DocProject/buildhelp/ 118 | DocProject/Help/*.HxT 119 | DocProject/Help/*.HxC 120 | DocProject/Help/*.hhc 121 | DocProject/Help/*.hhk 122 | DocProject/Help/*.hhp 123 | DocProject/Help/Html2 124 | DocProject/Help/html 125 | 126 | # Click-Once directory 127 | publish/ 128 | 129 | # Publish Web Output 130 | *.[Pp]ublish.xml 131 | *.azurePubxml 132 | # TODO: Comment the next line if you want to checkin your web deploy settings 133 | # but database connection strings (with potential passwords) will be unencrypted 134 | *.pubxml 135 | *.publishproj 136 | 137 | # NuGet Packages 138 | *.nupkg 139 | # The packages folder can be ignored because of Package Restore 140 | **/packages/* 141 | # except build/, which is used as an MSBuild target. 142 | !**/packages/build/ 143 | # Uncomment if necessary however generally it will be regenerated when needed 144 | #!**/packages/repositories.config 145 | 146 | # Windows Azure Build Output 147 | csx/ 148 | *.build.csdef 149 | 150 | # Windows Store app package directory 151 | AppPackages/ 152 | 153 | # Others 154 | *.[Cc]ache 155 | ClientBin/ 156 | [Ss]tyle[Cc]op.* 157 | ~$* 158 | *~ 159 | *.dbmdl 160 | *.dbproj.schemaview 161 | *.pfx 162 | *.publishsettings 163 | node_modules/ 164 | bower_components/ 165 | 166 | # RIA/Silverlight projects 167 | Generated_Code/ 168 | 169 | # Backup & report files from converting an old project file 170 | # to a newer Visual Studio version. Backup files are not needed, 171 | # because we have git ;-) 172 | _UpgradeReport_Files/ 173 | Backup*/ 174 | UpgradeLog*.XML 175 | UpgradeLog*.htm 176 | 177 | # SQL Server files 178 | *.mdf 179 | *.ldf 180 | 181 | # Business Intelligence projects 182 | *.rdl.data 183 | *.bim.layout 184 | *.bim_*.settings 185 | 186 | # Microsoft Fakes 187 | FakesAssemblies/ 188 | 189 | # Node.js Tools for Visual Studio 190 | .ntvs_analysis.dat 191 | 192 | # Visual Studio 6 build log 193 | *.plg 194 | 195 | # Visual Studio 6 workspace options file 196 | *.opt 197 | -------------------------------------------------------------------------------- /D2dControl.sln: -------------------------------------------------------------------------------- 1 |  2 | Microsoft Visual Studio Solution File, Format Version 12.00 3 | # Visual Studio 14 4 | VisualStudioVersion = 14.0.24720.0 5 | MinimumVisualStudioVersion = 10.0.40219.1 6 | Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "D2dControl", "D2dControl\D2dControl.csproj", "{F3ED9CEF-8E61-4B40-8E47-DE9A97B10301}" 7 | EndProject 8 | Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Sample", "Sample\Sample.csproj", "{059C082E-84E6-4027-8C04-FC41A3EE320E}" 9 | EndProject 10 | Global 11 | GlobalSection(SolutionConfigurationPlatforms) = preSolution 12 | Debug|Any CPU = Debug|Any CPU 13 | Release|Any CPU = Release|Any CPU 14 | EndGlobalSection 15 | GlobalSection(ProjectConfigurationPlatforms) = postSolution 16 | {F3ED9CEF-8E61-4B40-8E47-DE9A97B10301}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 17 | {F3ED9CEF-8E61-4B40-8E47-DE9A97B10301}.Debug|Any CPU.Build.0 = Debug|Any CPU 18 | {F3ED9CEF-8E61-4B40-8E47-DE9A97B10301}.Release|Any CPU.ActiveCfg = Release|Any CPU 19 | {F3ED9CEF-8E61-4B40-8E47-DE9A97B10301}.Release|Any CPU.Build.0 = Release|Any CPU 20 | {059C082E-84E6-4027-8C04-FC41A3EE320E}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 21 | {059C082E-84E6-4027-8C04-FC41A3EE320E}.Debug|Any CPU.Build.0 = Debug|Any CPU 22 | {059C082E-84E6-4027-8C04-FC41A3EE320E}.Release|Any CPU.ActiveCfg = Release|Any CPU 23 | {059C082E-84E6-4027-8C04-FC41A3EE320E}.Release|Any CPU.Build.0 = Release|Any CPU 24 | EndGlobalSection 25 | GlobalSection(SolutionProperties) = preSolution 26 | HideSolutionNode = FALSE 27 | EndGlobalSection 28 | EndGlobal 29 | -------------------------------------------------------------------------------- /D2dControl/D2dControl.cs: -------------------------------------------------------------------------------- 1 | using SharpDX; 2 | using SharpDX.Direct2D1; 3 | using SharpDX.Direct3D; 4 | using SharpDX.Direct3D11; 5 | using SharpDX.DXGI; 6 | using System; 7 | using System.Collections.Generic; 8 | using System.ComponentModel; 9 | using System.Diagnostics; 10 | using System.Windows; 11 | using System.Windows.Threading; 12 | 13 | namespace D2dControl { 14 | public abstract class D2dControl : System.Windows.Controls.Image { 15 | // - field ----------------------------------------------------------------------- 16 | 17 | private SharpDX.Direct3D11.Device device ; 18 | private Texture2D renderTarget ; 19 | private Dx11ImageSource d3DSurface ; 20 | private RenderTarget d2DRenderTarget; 21 | private SharpDX.Direct2D1.Factory d2DFactory ; 22 | 23 | private readonly Stopwatch renderTimer = new Stopwatch(); 24 | 25 | protected ResourceCache resCache = new ResourceCache(); 26 | 27 | private long lastFrameTime = 0; 28 | private long lastRenderTime = 0; 29 | private int frameCount = 0; 30 | private int frameCountHistTotal = 0; 31 | private Queue frameCountHist = new Queue(); 32 | 33 | // - property -------------------------------------------------------------------- 34 | 35 | public static bool IsInDesignMode { 36 | get { 37 | var prop = DesignerProperties.IsInDesignModeProperty; 38 | var isDesignMode = (bool)DependencyPropertyDescriptor.FromProperty(prop, typeof(FrameworkElement)).Metadata.DefaultValue; 39 | return isDesignMode; 40 | } 41 | } 42 | 43 | private static readonly DependencyPropertyKey FpsPropertyKey = DependencyProperty.RegisterReadOnly( 44 | "Fps", 45 | typeof(int), 46 | typeof(D2dControl), 47 | new FrameworkPropertyMetadata(0, FrameworkPropertyMetadataOptions.None) 48 | ); 49 | 50 | public static readonly DependencyProperty FpsProperty = FpsPropertyKey.DependencyProperty; 51 | 52 | public int Fps { 53 | get { return (int)GetValue( FpsProperty ); } 54 | protected set { SetValue( FpsPropertyKey, value ); } 55 | } 56 | 57 | public static DependencyProperty RenderWaitProperty = DependencyProperty.Register( 58 | "RenderWait", 59 | typeof(int), 60 | typeof(D2dControl), 61 | new FrameworkPropertyMetadata( 2, OnRenderWaitChanged ) 62 | ); 63 | 64 | public int RenderWait { 65 | get { return (int)GetValue( RenderWaitProperty ); } 66 | set { SetValue( RenderWaitProperty, value ); } 67 | } 68 | 69 | // - public methods -------------------------------------------------------------- 70 | 71 | public D2dControl() { 72 | base.Loaded += Window_Loaded; 73 | base.Unloaded += Window_Closing; 74 | 75 | base.Stretch = System.Windows.Media.Stretch.Fill; 76 | } 77 | 78 | public abstract void Render( RenderTarget target ); 79 | 80 | // - event handler --------------------------------------------------------------- 81 | 82 | private void Window_Loaded( object sender, RoutedEventArgs e ) { 83 | if ( D2dControl.IsInDesignMode ) { 84 | return; 85 | } 86 | 87 | StartD3D(); 88 | StartRendering(); 89 | } 90 | 91 | private void Window_Closing( object sender, RoutedEventArgs e ) { 92 | if ( D2dControl.IsInDesignMode ) { 93 | return; 94 | } 95 | 96 | StopRendering(); 97 | EndD3D(); 98 | } 99 | 100 | private void OnRendering( object sender, EventArgs e ) { 101 | if ( !renderTimer.IsRunning ) { 102 | return; 103 | } 104 | 105 | PrepareAndCallRender(); 106 | d3DSurface.InvalidateD3DImage(); 107 | 108 | lastRenderTime = renderTimer.ElapsedMilliseconds; 109 | } 110 | 111 | protected override void OnRenderSizeChanged( SizeChangedInfo sizeInfo ) { 112 | CreateAndBindTargets(); 113 | base.OnRenderSizeChanged( sizeInfo ); 114 | } 115 | 116 | private void OnIsFrontBufferAvailableChanged( object sender, DependencyPropertyChangedEventArgs e ) { 117 | if ( d3DSurface.IsFrontBufferAvailable ) { 118 | StartRendering(); 119 | } else { 120 | StopRendering(); 121 | } 122 | } 123 | 124 | private static void OnRenderWaitChanged(DependencyObject d, DependencyPropertyChangedEventArgs e) { 125 | var control = (D2dControl)d; 126 | control.d3DSurface.RenderWait = (int)e.NewValue; 127 | } 128 | 129 | // - private methods ------------------------------------------------------------- 130 | 131 | private void StartD3D() { 132 | device = new SharpDX.Direct3D11.Device( DriverType.Hardware, DeviceCreationFlags.BgraSupport ); 133 | 134 | d3DSurface = new Dx11ImageSource(); 135 | d3DSurface.IsFrontBufferAvailableChanged += OnIsFrontBufferAvailableChanged; 136 | 137 | CreateAndBindTargets(); 138 | 139 | base.Source = d3DSurface; 140 | } 141 | 142 | private void EndD3D() { 143 | d3DSurface.IsFrontBufferAvailableChanged -= OnIsFrontBufferAvailableChanged; 144 | base.Source = null; 145 | 146 | Disposer.SafeDispose( ref d2DRenderTarget ); 147 | Disposer.SafeDispose( ref d2DFactory ); 148 | Disposer.SafeDispose( ref d3DSurface ); 149 | Disposer.SafeDispose( ref renderTarget ); 150 | Disposer.SafeDispose( ref device ); 151 | } 152 | 153 | private void CreateAndBindTargets() 154 | { 155 | if (d3DSurface == null) { 156 | return; 157 | } 158 | 159 | d3DSurface.SetRenderTarget( null ); 160 | 161 | Disposer.SafeDispose( ref d2DRenderTarget ); 162 | Disposer.SafeDispose( ref d2DFactory ); 163 | Disposer.SafeDispose( ref renderTarget ); 164 | 165 | var width = Math.Max((int)ActualWidth , 100); 166 | var height = Math.Max((int)ActualHeight, 100); 167 | 168 | var renderDesc = new Texture2DDescription { 169 | BindFlags = BindFlags.RenderTarget | BindFlags.ShaderResource, 170 | Format = Format.B8G8R8A8_UNorm, 171 | Width = width, 172 | Height = height, 173 | MipLevels = 1, 174 | SampleDescription = new SampleDescription(1, 0), 175 | Usage = ResourceUsage.Default, 176 | OptionFlags = ResourceOptionFlags.Shared, 177 | CpuAccessFlags = CpuAccessFlags.None, 178 | ArraySize = 1 179 | }; 180 | 181 | renderTarget = new Texture2D( device, renderDesc ); 182 | 183 | var surface = renderTarget.QueryInterface(); 184 | 185 | d2DFactory = new SharpDX.Direct2D1.Factory(); 186 | var rtp = new RenderTargetProperties(new PixelFormat(Format.Unknown, SharpDX.Direct2D1.AlphaMode.Premultiplied)); 187 | d2DRenderTarget = new RenderTarget( d2DFactory, surface, rtp ); 188 | resCache.RenderTarget = d2DRenderTarget; 189 | 190 | d3DSurface.SetRenderTarget( renderTarget ); 191 | 192 | device.ImmediateContext.Rasterizer.SetViewport( 0, 0, width, height, 0.0f, 1.0f ); 193 | } 194 | 195 | private void StartRendering() { 196 | if ( renderTimer.IsRunning ) { 197 | return; 198 | } 199 | 200 | System.Windows.Media.CompositionTarget.Rendering += OnRendering; 201 | renderTimer.Start(); 202 | } 203 | 204 | private void StopRendering() { 205 | if ( !renderTimer.IsRunning ) { 206 | return; 207 | } 208 | 209 | System.Windows.Media.CompositionTarget.Rendering -= OnRendering; 210 | renderTimer.Stop(); 211 | } 212 | 213 | private void PrepareAndCallRender() { 214 | if ( device == null ) { 215 | return; 216 | } 217 | 218 | d2DRenderTarget.BeginDraw(); 219 | Render( d2DRenderTarget ); 220 | d2DRenderTarget.EndDraw(); 221 | 222 | CalcFps(); 223 | 224 | device.ImmediateContext.Flush(); 225 | } 226 | 227 | private void CalcFps() { 228 | frameCount++; 229 | if ( renderTimer.ElapsedMilliseconds - lastFrameTime > 1000 ) { 230 | frameCountHist.Enqueue( frameCount ); 231 | frameCountHistTotal += frameCount; 232 | if ( frameCountHist.Count > 5 ) { 233 | frameCountHistTotal -= frameCountHist.Dequeue(); 234 | } 235 | 236 | Fps = frameCountHistTotal / frameCountHist.Count; 237 | 238 | frameCount = 0; 239 | lastFrameTime = renderTimer.ElapsedMilliseconds; 240 | } 241 | } 242 | } 243 | } 244 | -------------------------------------------------------------------------------- /D2dControl/D2dControl.csproj: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | Debug 6 | AnyCPU 7 | {F3ED9CEF-8E61-4B40-8E47-DE9A97B10301} 8 | Library 9 | Properties 10 | D2dControl 11 | D2dControl 12 | v4.5.2 13 | 512 14 | 15 | 16 | 17 | 18 | true 19 | full 20 | false 21 | bin\Debug\ 22 | DEBUG;TRACE 23 | prompt 24 | 4 25 | 26 | 27 | pdbonly 28 | true 29 | bin\Release\ 30 | TRACE 31 | prompt 32 | 4 33 | 34 | 35 | 36 | 37 | 38 | ..\packages\SharpDX.3.0.0\lib\net45\SharpDX.dll 39 | True 40 | 41 | 42 | ..\packages\SharpDX.Direct2D1.3.0.0\lib\net45\SharpDX.Direct2D1.dll 43 | True 44 | 45 | 46 | ..\packages\SharpDX.Direct3D11.3.0.0\lib\net45\SharpDX.Direct3D11.dll 47 | True 48 | 49 | 50 | ..\packages\SharpDX.Direct3D9.3.0.0\lib\net45\SharpDX.Direct3D9.dll 51 | True 52 | 53 | 54 | ..\packages\SharpDX.DXGI.3.0.0\lib\net45\SharpDX.DXGI.dll 55 | True 56 | 57 | 58 | 59 | 60 | 61 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | 70 | 71 | 72 | 73 | 74 | 75 | 76 | 77 | 78 | 79 | 80 | 81 | 82 | 89 | -------------------------------------------------------------------------------- /D2dControl/D2dControl.nuspec: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | $id$ 5 | $version$ 6 | $author$ 7 | https://github.com/dalance/D2dControl 8 | https://raw.githubusercontent.com/dalance/D2dControl/master/LICENSE 9 | false 10 | $description$ 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | -------------------------------------------------------------------------------- /D2dControl/Disposer.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | namespace D2dControl { 4 | public static class Disposer { 5 | public static void SafeDispose( ref T resource ) where T : class { 6 | if ( resource == null ) { 7 | return; 8 | } 9 | 10 | var disposer = resource as IDisposable; 11 | if ( disposer != null ) { 12 | try { 13 | disposer.Dispose(); 14 | } catch { 15 | } 16 | } 17 | 18 | resource = null; 19 | } 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /D2dControl/Dx11ImageSource.cs: -------------------------------------------------------------------------------- 1 | using SharpDX.Direct3D9; 2 | using System; 3 | using System.Threading; 4 | using System.Windows.Interop; 5 | 6 | namespace D2dControl { 7 | class Dx11ImageSource : D3DImage, IDisposable { 8 | 9 | // - field ----------------------------------------------------------------------- 10 | 11 | private static int ActiveClients; 12 | private static Direct3DEx D3DContext; 13 | private static DeviceEx D3DDevice; 14 | 15 | private Texture renderTarget; 16 | 17 | // - property -------------------------------------------------------------------- 18 | 19 | public int RenderWait { get; set; } = 2; // default: 2ms 20 | 21 | // - public methods -------------------------------------------------------------- 22 | 23 | public Dx11ImageSource() { 24 | StartD3D(); 25 | Dx11ImageSource.ActiveClients++; 26 | } 27 | 28 | public void Dispose() { 29 | SetRenderTarget( null ); 30 | 31 | Disposer.SafeDispose( ref renderTarget ); 32 | 33 | Dx11ImageSource.ActiveClients--; 34 | EndD3D(); 35 | } 36 | 37 | public void InvalidateD3DImage() { 38 | if( renderTarget != null ) { 39 | base.Lock(); 40 | if( RenderWait != 0 ) { 41 | Thread.Sleep( RenderWait ); 42 | } 43 | base.AddDirtyRect( new System.Windows.Int32Rect( 0, 0, base.PixelWidth, base.PixelHeight ) ); 44 | base.Unlock(); 45 | } 46 | } 47 | 48 | public void SetRenderTarget( SharpDX.Direct3D11.Texture2D target ) { 49 | if( renderTarget != null ) { 50 | renderTarget = null; 51 | 52 | base.Lock(); 53 | base.SetBackBuffer( D3DResourceType.IDirect3DSurface9, IntPtr.Zero ); 54 | base.Unlock(); 55 | } 56 | 57 | if( target == null ) { 58 | return; 59 | } 60 | 61 | var format = Dx11ImageSource.TranslateFormat( target ); 62 | var handle = GetSharedHandle( target ); 63 | 64 | if ( !IsShareable( target ) ) { 65 | throw new ArgumentException( "Texture must be created with ResouceOptionFlags.Shared" ); 66 | } 67 | 68 | if ( format == Format.Unknown ) { 69 | throw new ArgumentException( "Texture format is not compatible with OpenSharedResouce" ); 70 | } 71 | 72 | if ( handle == IntPtr.Zero ) { 73 | throw new ArgumentException( "Invalid handle" ); 74 | } 75 | 76 | renderTarget = new Texture( Dx11ImageSource.D3DDevice, target.Description.Width, target.Description.Height, 1, Usage.RenderTarget, format, Pool.Default, ref handle ); 77 | 78 | using( var surface = renderTarget.GetSurfaceLevel( 0 ) ) { 79 | base.Lock(); 80 | base.SetBackBuffer( D3DResourceType.IDirect3DSurface9, surface.NativePointer ); 81 | base.Unlock(); 82 | } 83 | } 84 | 85 | // - private methods ------------------------------------------------------------- 86 | 87 | private void StartD3D() { 88 | if( Dx11ImageSource.ActiveClients != 0 ) { 89 | return; 90 | } 91 | 92 | var presentParams = GetPresentParameters(); 93 | var createFlags = CreateFlags.HardwareVertexProcessing | CreateFlags.Multithreaded | CreateFlags.FpuPreserve; 94 | 95 | Dx11ImageSource.D3DContext = new Direct3DEx(); 96 | Dx11ImageSource.D3DDevice = new DeviceEx( D3DContext, 0, DeviceType.Hardware, IntPtr.Zero, createFlags, presentParams ); 97 | } 98 | 99 | private void EndD3D() { 100 | if( Dx11ImageSource.ActiveClients != 0 ) { 101 | return; 102 | } 103 | 104 | Disposer.SafeDispose( ref renderTarget ); 105 | Disposer.SafeDispose( ref Dx11ImageSource.D3DDevice ); 106 | Disposer.SafeDispose( ref Dx11ImageSource.D3DContext ); 107 | } 108 | 109 | private static void ResetD3D() { 110 | if( Dx11ImageSource.ActiveClients == 0 ) { 111 | return; 112 | } 113 | 114 | var presentParams = GetPresentParameters(); 115 | Dx11ImageSource.D3DDevice.ResetEx( ref presentParams ); 116 | } 117 | 118 | private static PresentParameters GetPresentParameters() { 119 | var presentParams = new PresentParameters(); 120 | 121 | presentParams.Windowed = true; 122 | presentParams.SwapEffect = SwapEffect.Discard; 123 | presentParams.DeviceWindowHandle = NativeMethods.GetDesktopWindow(); 124 | presentParams.PresentationInterval = PresentInterval.Default; 125 | 126 | return presentParams; 127 | } 128 | 129 | private IntPtr GetSharedHandle( SharpDX.Direct3D11.Texture2D texture ) { 130 | using ( var resource = texture.QueryInterface() ) { 131 | return resource.SharedHandle; 132 | } 133 | } 134 | 135 | private static Format TranslateFormat( SharpDX.Direct3D11.Texture2D texture ) { 136 | switch( texture.Description.Format ) { 137 | case SharpDX.DXGI.Format.R10G10B10A2_UNorm : return SharpDX.Direct3D9.Format.A2B10G10R10; 138 | case SharpDX.DXGI.Format.R16G16B16A16_Float: return SharpDX.Direct3D9.Format.A16B16G16R16F; 139 | case SharpDX.DXGI.Format.B8G8R8A8_UNorm : return SharpDX.Direct3D9.Format.A8R8G8B8; 140 | default : return SharpDX.Direct3D9.Format.Unknown; 141 | } 142 | } 143 | 144 | private static bool IsShareable( SharpDX.Direct3D11.Texture2D texture ) { 145 | return ( texture.Description.OptionFlags & SharpDX.Direct3D11.ResourceOptionFlags.Shared ) != 0; 146 | } 147 | } 148 | } 149 | -------------------------------------------------------------------------------- /D2dControl/NativeMethods.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Runtime.InteropServices; 3 | 4 | namespace D2dControl { 5 | public static class NativeMethods { 6 | [DllImport( "user32.dll", SetLastError = false )] 7 | public static extern IntPtr GetDesktopWindow(); 8 | } 9 | } 10 | -------------------------------------------------------------------------------- /D2dControl/Properties/AssemblyInfo.cs: -------------------------------------------------------------------------------- 1 | using System.Reflection; 2 | using System.Runtime.CompilerServices; 3 | using System.Runtime.InteropServices; 4 | 5 | // アセンブリに関する一般情報は以下の属性セットをとおして制御されます。 6 | // アセンブリに関連付けられている情報を変更するには、 7 | // これらの属性値を変更してください。 8 | [assembly: AssemblyTitle("D2dControl")] 9 | [assembly: AssemblyDescription("WPF Control for Direct2D with SharpDX")] 10 | [assembly: AssemblyConfiguration("")] 11 | [assembly: AssemblyCompany("dalance")] 12 | [assembly: AssemblyProduct("D2dControl")] 13 | [assembly: AssemblyCopyright("Copyright © 2015")] 14 | [assembly: AssemblyTrademark("")] 15 | [assembly: AssemblyCulture("")] 16 | 17 | // ComVisible を false に設定すると、その型はこのアセンブリ内で COM コンポーネントから 18 | // 参照不可能になります。COM からこのアセンブリ内の型にアクセスする場合は、 19 | // その型の ComVisible 属性を true に設定してください。 20 | [assembly: ComVisible(false)] 21 | 22 | // このプロジェクトが COM に公開される場合、次の GUID が typelib の ID になります 23 | [assembly: Guid("f3ed9cef-8e61-4b40-8e47-de9a97b10301")] 24 | 25 | // アセンブリのバージョン情報は次の 4 つの値で構成されています: 26 | // 27 | // メジャー バージョン 28 | // マイナー バージョン 29 | // ビルド番号 30 | // Revision 31 | // 32 | // すべての値を指定するか、下のように '*' を使ってビルドおよびリビジョン番号を 33 | // 既定値にすることができます: 34 | // [assembly: AssemblyVersion("1.0.*")] 35 | [assembly: AssemblyVersion( "1.1.0.0" )] 36 | [assembly: AssemblyFileVersion( "1.1.0.0" )] 37 | -------------------------------------------------------------------------------- /D2dControl/ResourceCache.cs: -------------------------------------------------------------------------------- 1 | using SharpDX.Direct2D1; 2 | using System; 3 | using System.Collections.Generic; 4 | 5 | namespace D2dControl { 6 | public class ResourceCache { 7 | // - field ----------------------------------------------------------------------- 8 | 9 | private Dictionary> generators = new Dictionary>(); 10 | private Dictionary resources = new Dictionary(); 11 | private RenderTarget renderTarget = null; 12 | 13 | // - property -------------------------------------------------------------------- 14 | 15 | public RenderTarget RenderTarget { 16 | get { return renderTarget; } 17 | set { renderTarget = value; UpdateResources(); } 18 | } 19 | 20 | public int Count { 21 | get { return resources.Count; } 22 | } 23 | 24 | public object this[string key] { 25 | get { return resources[key]; } 26 | } 27 | 28 | public Dictionary.KeyCollection Keys { 29 | get { return resources.Keys; } 30 | } 31 | 32 | public Dictionary.ValueCollection Values { 33 | get { return resources.Values; } 34 | } 35 | 36 | // - public methods -------------------------------------------------------------- 37 | 38 | public void Add( string key, Func gen ) { 39 | object resOld; 40 | if ( resources.TryGetValue( key, out resOld ) ) { 41 | Disposer.SafeDispose( ref resOld ); 42 | generators.Remove( key ); 43 | resources.Remove( key ); 44 | } 45 | 46 | if ( renderTarget == null ) { 47 | generators.Add( key, gen ); 48 | resources.Add( key, null ); 49 | } else { 50 | var res = gen( renderTarget ); 51 | generators.Add( key, gen ); 52 | resources.Add( key, res ); 53 | } 54 | } 55 | 56 | public void Clear() { 57 | foreach ( var key in resources.Keys ) { 58 | var res = resources[key]; 59 | Disposer.SafeDispose( ref res ); 60 | } 61 | generators.Clear(); 62 | resources.Clear(); 63 | } 64 | 65 | public bool ContainsKey( string key ) { 66 | return resources.ContainsKey( key ); 67 | } 68 | 69 | public bool ContainsValue( object val ) { 70 | return resources.ContainsValue( val ); 71 | } 72 | 73 | public Dictionary.Enumerator GetEnumerator() { 74 | return resources.GetEnumerator(); 75 | } 76 | 77 | public bool Remove( string key ) { 78 | object res; 79 | if ( resources.TryGetValue( key, out res ) ) { 80 | Disposer.SafeDispose( ref res ); 81 | generators.Remove( key ); 82 | resources.Remove( key ); 83 | return true; 84 | } else { 85 | return false; 86 | } 87 | } 88 | 89 | public bool TryGetValue( string key, out object res ) { 90 | return resources.TryGetValue( key, out res ); 91 | } 92 | 93 | // - private methods ------------------------------------------------------------- 94 | 95 | private void UpdateResources() { 96 | if ( renderTarget == null ) { return; } 97 | 98 | foreach( var g in generators ) { 99 | var key = g.Key; 100 | var gen = g.Value; 101 | var res = gen( renderTarget ); 102 | 103 | object resOld; 104 | if ( resources.TryGetValue( key, out resOld ) ) { 105 | Disposer.SafeDispose( ref resOld ); 106 | resources.Remove( key ); 107 | } 108 | 109 | resources.Add( key, res ); 110 | } 111 | } 112 | } 113 | } 114 | -------------------------------------------------------------------------------- /D2dControl/app.config: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | -------------------------------------------------------------------------------- /D2dControl/packages.config: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) 2015 dalance 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | 23 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # D2dControl 2 | 3 | [![Build status](https://ci.appveyor.com/api/projects/status/ey3x8chjrxwa967s?svg=true)](https://ci.appveyor.com/project/dalance/d2dcontrol) 4 | 5 | **D2dControl** is a WPF Control for Direct2D with SharpDX. 6 | 7 | ## Install 8 | Download from [nuget](https://www.nuget.org/packages/D2dControl/) 9 | 10 | ## Dependencies 11 | - SharpDX ( >= 3.0.0 ) 12 | 13 | ## Usage 14 | Create a class derived from `D2dControl.D2dControl`, and override `Render` method. 15 | In `Render` method, you can use `SharpDX.Direct2D1.RenderTarget` for calling Direct2D functions. 16 | See [sample project](https://github.com/dalance/D2dControl/tree/master/Sample) for details. -------------------------------------------------------------------------------- /Sample/App.config: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | -------------------------------------------------------------------------------- /Sample/App.xaml: -------------------------------------------------------------------------------- 1 |  6 | 7 | 8 | 9 | 10 | -------------------------------------------------------------------------------- /Sample/App.xaml.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Configuration; 4 | using System.Data; 5 | using System.Linq; 6 | using System.Threading.Tasks; 7 | using System.Windows; 8 | 9 | namespace Sample { 10 | /// 11 | /// App.xaml の相互作用ロジック 12 | /// 13 | public partial class App : Application { 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /Sample/MainWindow.xaml: -------------------------------------------------------------------------------- 1 |  9 | 10 | 11 | 13 | 14 | -------------------------------------------------------------------------------- /Sample/MainWindow.xaml.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using System.Threading.Tasks; 6 | using System.Windows; 7 | using System.Windows.Controls; 8 | using System.Windows.Data; 9 | using System.Windows.Documents; 10 | using System.Windows.Input; 11 | using System.Windows.Media; 12 | using System.Windows.Media.Imaging; 13 | using System.Windows.Navigation; 14 | using System.Windows.Shapes; 15 | 16 | namespace Sample { 17 | /// 18 | /// MainWindow.xaml の相互作用ロジック 19 | /// 20 | public partial class MainWindow : Window { 21 | public MainWindow() { 22 | InitializeComponent(); 23 | } 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /Sample/Properties/AssemblyInfo.cs: -------------------------------------------------------------------------------- 1 | using System.Reflection; 2 | using System.Resources; 3 | using System.Runtime.CompilerServices; 4 | using System.Runtime.InteropServices; 5 | using System.Windows; 6 | 7 | // アセンブリに関する一般情報は以下の属性セットをとおして制御されます。 8 | // アセンブリに関連付けられている情報を変更するには、 9 | // これらの属性値を変更してください。 10 | [assembly: AssemblyTitle( "Sample" )] 11 | [assembly: AssemblyDescription( "" )] 12 | [assembly: AssemblyConfiguration( "" )] 13 | [assembly: AssemblyCompany( "" )] 14 | [assembly: AssemblyProduct( "Sample" )] 15 | [assembly: AssemblyCopyright( "Copyright © 2015" )] 16 | [assembly: AssemblyTrademark( "" )] 17 | [assembly: AssemblyCulture( "" )] 18 | 19 | // ComVisible を false に設定すると、その型はこのアセンブリ内で COM コンポーネントから 20 | // 参照不可能になります。COM からこのアセンブリ内の型にアクセスする場合は、 21 | // その型の ComVisible 属性を true に設定してください。 22 | [assembly: ComVisible( false )] 23 | 24 | //ローカライズ可能なアプリケーションのビルドを開始するには、 25 | //.csproj ファイルの CultureYouAreCodingWith を 26 | // 内部で設定します。たとえば、 27 | //ソース ファイルで英語を使用している場合、 を en-US に設定します。次に、 28 | //下の NeutralResourceLanguage 属性のコメントを解除します。下の行の "en-US" を 29 | //プロジェクト ファイルの UICulture 設定と一致するよう更新します。 30 | 31 | //[assembly: NeutralResourcesLanguage("en-US", UltimateResourceFallbackLocation.Satellite)] 32 | 33 | 34 | [assembly: ThemeInfo( 35 | ResourceDictionaryLocation.None, //テーマ固有のリソース ディクショナリが置かれている場所 36 | //(リソースがページ、 37 | //またはアプリケーション リソース ディクショナリに見つからない場合に使用されます) 38 | ResourceDictionaryLocation.SourceAssembly //汎用リソース ディクショナリが置かれている場所 39 | //(リソースがページ、 40 | //アプリケーション、またはいずれのテーマ固有のリソース ディクショナリにも見つからない場合に使用されます) 41 | )] 42 | 43 | 44 | // アセンブリのバージョン情報は次の 4 つの値で構成されています: 45 | // 46 | // メジャー バージョン 47 | // マイナー バージョン 48 | // ビルド番号 49 | // Revision 50 | // 51 | // すべての値を指定するか、下のように '*' を使ってビルドおよびリビジョン番号を 52 | // 既定値にすることができます: 53 | // [assembly: AssemblyVersion("1.0.*")] 54 | [assembly: AssemblyVersion( "1.0.0.0" )] 55 | [assembly: AssemblyFileVersion( "1.0.0.0" )] 56 | -------------------------------------------------------------------------------- /Sample/Properties/Resources.Designer.cs: -------------------------------------------------------------------------------- 1 | //------------------------------------------------------------------------------ 2 | // 3 | // このコードはツールによって生成されました。 4 | // ランタイム バージョン:4.0.30319.42000 5 | // 6 | // このファイルへの変更は、以下の状況下で不正な動作の原因になったり、 7 | // コードが再生成されるときに損失したりします 8 | // 9 | //------------------------------------------------------------------------------ 10 | 11 | namespace Sample.Properties { 12 | 13 | 14 | /// 15 | /// ローカライズされた文字列などを検索するための、厳密に型指定されたリソース クラスです。 16 | /// 17 | // このクラスは StronglyTypedResourceBuilder クラスによって ResGen 18 | // または Visual Studio のようなツールを使用して自動生成されました。 19 | // メンバーを追加または削除するには、.ResX ファイルを編集して、/str オプションと共に 20 | // ResGen を実行し直すか、または VS プロジェクトをリビルドします。 21 | [global::System.CodeDom.Compiler.GeneratedCodeAttribute( "System.Resources.Tools.StronglyTypedResourceBuilder", "4.0.0.0" )] 22 | [global::System.Diagnostics.DebuggerNonUserCodeAttribute()] 23 | [global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()] 24 | internal class Resources { 25 | 26 | private static global::System.Resources.ResourceManager resourceMan; 27 | 28 | private static global::System.Globalization.CultureInfo resourceCulture; 29 | 30 | [global::System.Diagnostics.CodeAnalysis.SuppressMessageAttribute( "Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode" )] 31 | internal Resources() { 32 | } 33 | 34 | /// 35 | /// このクラスで使用されるキャッシュされた ResourceManager インスタンスを返します。 36 | /// 37 | [global::System.ComponentModel.EditorBrowsableAttribute( global::System.ComponentModel.EditorBrowsableState.Advanced )] 38 | internal static global::System.Resources.ResourceManager ResourceManager { 39 | get { 40 | if ( ( resourceMan == null ) ) { 41 | global::System.Resources.ResourceManager temp = new global::System.Resources.ResourceManager("Sample.Properties.Resources", typeof(Resources).Assembly); 42 | resourceMan = temp; 43 | } 44 | return resourceMan; 45 | } 46 | } 47 | 48 | /// 49 | /// 厳密に型指定されたこのリソース クラスを使用して、すべての検索リソースに対し、 50 | /// 現在のスレッドの CurrentUICulture プロパティをオーバーライドします。 51 | /// 52 | [global::System.ComponentModel.EditorBrowsableAttribute( global::System.ComponentModel.EditorBrowsableState.Advanced )] 53 | internal static global::System.Globalization.CultureInfo Culture { 54 | get { 55 | return resourceCulture; 56 | } 57 | set { 58 | resourceCulture = value; 59 | } 60 | } 61 | } 62 | } 63 | -------------------------------------------------------------------------------- /Sample/Properties/Resources.resx: -------------------------------------------------------------------------------- 1 |  2 | 3 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | 70 | 71 | 72 | 73 | 74 | 75 | 76 | 77 | 78 | 79 | 80 | 81 | 82 | 83 | 84 | 85 | 86 | 87 | 88 | 89 | 90 | 91 | 92 | 93 | 94 | 95 | 96 | 97 | 98 | 99 | 100 | 101 | 102 | 103 | 104 | 105 | 106 | text/microsoft-resx 107 | 108 | 109 | 2.0 110 | 111 | 112 | System.Resources.ResXResourceReader, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 113 | 114 | 115 | System.Resources.ResXResourceWriter, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 116 | 117 | -------------------------------------------------------------------------------- /Sample/Properties/Settings.Designer.cs: -------------------------------------------------------------------------------- 1 | //------------------------------------------------------------------------------ 2 | // 3 | // This code was generated by a tool. 4 | // Runtime Version:4.0.30319.42000 5 | // 6 | // Changes to this file may cause incorrect behavior and will be lost if 7 | // the code is regenerated. 8 | // 9 | //------------------------------------------------------------------------------ 10 | 11 | namespace Sample.Properties { 12 | 13 | 14 | [global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()] 15 | [global::System.CodeDom.Compiler.GeneratedCodeAttribute( "Microsoft.VisualStudio.Editors.SettingsDesigner.SettingsSingleFileGenerator", "11.0.0.0" )] 16 | internal sealed partial class Settings : global::System.Configuration.ApplicationSettingsBase { 17 | 18 | private static Settings defaultInstance = ((Settings)(global::System.Configuration.ApplicationSettingsBase.Synchronized(new Settings()))); 19 | 20 | public static Settings Default { 21 | get { 22 | return defaultInstance; 23 | } 24 | } 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /Sample/Properties/Settings.settings: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | 6 | 7 | -------------------------------------------------------------------------------- /Sample/Sample.csproj: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | Debug 6 | AnyCPU 7 | {059C082E-84E6-4027-8C04-FC41A3EE320E} 8 | WinExe 9 | Properties 10 | Sample 11 | Sample 12 | v4.5.2 13 | 512 14 | {60dc8134-eba5-43b8-bcc9-bb4bc16c2548};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC} 15 | 4 16 | true 17 | 18 | 19 | 20 | 21 | AnyCPU 22 | true 23 | full 24 | false 25 | bin\Debug\ 26 | DEBUG;TRACE 27 | prompt 28 | 4 29 | 30 | 31 | AnyCPU 32 | pdbonly 33 | true 34 | bin\Release\ 35 | TRACE 36 | prompt 37 | 4 38 | 39 | 40 | 41 | ..\packages\SharpDX.3.0.0\lib\net45\SharpDX.dll 42 | True 43 | 44 | 45 | ..\packages\SharpDX.Direct2D1.3.0.0\lib\net45\SharpDX.Direct2D1.dll 46 | True 47 | 48 | 49 | ..\packages\SharpDX.DXGI.3.0.0\lib\net45\SharpDX.DXGI.dll 50 | True 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | 63 | 4.0 64 | 65 | 66 | 67 | 68 | 69 | 70 | 71 | MSBuild:Compile 72 | Designer 73 | 74 | 75 | 76 | MSBuild:Compile 77 | Designer 78 | 79 | 80 | App.xaml 81 | Code 82 | 83 | 84 | MainWindow.xaml 85 | Code 86 | 87 | 88 | 89 | 90 | Code 91 | 92 | 93 | True 94 | True 95 | Resources.resx 96 | 97 | 98 | True 99 | Settings.settings 100 | True 101 | 102 | 103 | ResXFileCodeGenerator 104 | Resources.Designer.cs 105 | 106 | 107 | 108 | SettingsSingleFileGenerator 109 | Settings.Designer.cs 110 | 111 | 112 | 113 | 114 | 115 | 116 | 117 | 118 | {f3ed9cef-8e61-4b40-8e47-de9a97b10301} 119 | D2dControl 120 | 121 | 122 | 123 | 130 | -------------------------------------------------------------------------------- /Sample/SampleControl.cs: -------------------------------------------------------------------------------- 1 | using SharpDX; 2 | using SharpDX.Direct2D1; 3 | using SharpDX.Mathematics.Interop; 4 | using System; 5 | 6 | namespace Sample { 7 | class SampleControl : D2dControl.D2dControl { 8 | 9 | private float x = 0; 10 | private float y = 0; 11 | private float w = 10; 12 | private float h = 10; 13 | private float dx = 1; 14 | private float dy = 1; 15 | 16 | private Random rnd = new Random(); 17 | 18 | public SampleControl() { 19 | resCache.Add( "RedBrush" , t => new SolidColorBrush( t, new RawColor4( 1.0f, 0.0f, 0.0f, 1.0f ) ) ); 20 | resCache.Add( "GreenBrush", t => new SolidColorBrush( t, new RawColor4( 0.0f, 1.0f, 0.0f, 1.0f ) ) ); 21 | resCache.Add( "BlueBrush" , t => new SolidColorBrush( t, new RawColor4( 0.0f, 0.0f, 1.0f, 1.0f ) ) ); 22 | } 23 | 24 | public override void Render( RenderTarget target ) { 25 | target.Clear( new RawColor4( 1.0f, 1.0f, 1.0f, 1.0f ) ); 26 | Brush brush = null; 27 | switch( rnd.Next( 3 ) ) { 28 | case 0: brush = resCache["RedBrush" ] as Brush; break; 29 | case 1: brush = resCache["GreenBrush"] as Brush; break; 30 | case 2: brush = resCache["BlueBrush" ] as Brush; break; 31 | } 32 | target.DrawRectangle( new RawRectangleF( x, y, x + w, y + h ), brush ); 33 | 34 | x = x + dx; 35 | y = y + dy; 36 | if ( x >= ActualWidth - w || x <= 0 ) { 37 | dx = -dx; 38 | } 39 | if ( y >= ActualHeight - h || y <= 0 ) { 40 | dy = -dy; 41 | } 42 | } 43 | } 44 | } 45 | -------------------------------------------------------------------------------- /Sample/packages.config: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | 6 | --------------------------------------------------------------------------------