From a490102e4b8d8f2b6828a47d17a97ef7bac9a39b Mon Sep 17 00:00:00 2001 From: "Juan J. Chiw" Date: Wed, 9 Apr 2014 13:01:51 +0200 Subject: [PATCH 1/2] Bugfixes in windows phone user control an sample In the sample project when you try to enter for second time in the custom layout there was an exception, because the custom layer is never detached from the previous ScanPage.xaml this was the exception 'gridCustomOverlay.Children.Add(CustomOverlay)' threw an exception of type 'System.InvalidOperationException' base: {System.InvalidOperationException: Element is already the child of another element. at MS.Internal.XcpImports.CheckHResult(UInt32 hr) at MS.Internal.XcpImports.Collection_AddValue[T](PresentationFrameworkCollection`1 collection, CValue value) at MS.Internal.XcpImports.Collection_AddDependencyObject[T](PresentationFrameworkCollection`1 collection, DependencyObject value) at System.Windows.PresentationFrameworkCollection`1.AddDependencyObject(DependencyObject value) at System.Windows.Controls.UIElementCollection.AddInternal(UIElement value) at System.Windows.PresentationFrameworkCollection`1.Add(T value)} The action to the buttons (cancel and torch) of the custom layer were only added once, because the buttons where already wired with an action. All the events in ScanPage are set to null when it's navigated from the page, because the Events are static and we were adding action everytime we navigated to the page --- .../Sample.WindowsPhone8/MainPage.xaml.cs | 20 +++++++++---------- .../WindowsPhone/ScanPage.xaml.cs | 15 +++++++++++--- .../WindowsPhone/ZXingScannerControl.xaml.cs | 1 + 3 files changed, 23 insertions(+), 13 deletions(-) diff --git a/Samples/WindowsPhone8/Sample.WindowsPhone8/MainPage.xaml.cs b/Samples/WindowsPhone8/Sample.WindowsPhone8/MainPage.xaml.cs index 61f930a06..ffef009d6 100644 --- a/Samples/WindowsPhone8/Sample.WindowsPhone8/MainPage.xaml.cs +++ b/Samples/WindowsPhone8/Sample.WindowsPhone8/MainPage.xaml.cs @@ -53,17 +53,17 @@ private void buttonScanCustom_Click(object sender, RoutedEventArgs e) { customOverlayElement = this.customOverlay.Children[0]; this.customOverlay.Children.RemoveAt(0); - } - //Wireup our buttons from the custom overlay - this.buttonCancel.Click += (s, e2) => - { - scanner.Cancel(); - }; - this.buttonFlash.Click += (s, e2) => - { - scanner.ToggleTorch(); - }; + //Wireup our buttons from the custom overlay + this.buttonCancel.Click += (s, e2) => + { + scanner.Cancel(); + }; + this.buttonFlash.Click += (s, e2) => + { + scanner.ToggleTorch(); + }; + } //Set our custom overlay and enable it scanner.CustomOverlay = customOverlayElement; diff --git a/src/ZXing.Net.Mobile/WindowsPhone/ScanPage.xaml.cs b/src/ZXing.Net.Mobile/WindowsPhone/ScanPage.xaml.cs index 4ffac320d..feacc7bce 100644 --- a/src/ZXing.Net.Mobile/WindowsPhone/ScanPage.xaml.cs +++ b/src/ZXing.Net.Mobile/WindowsPhone/ScanPage.xaml.cs @@ -35,14 +35,14 @@ public partial class ScanPage : PhoneApplicationPage public static event Action OnRequestAutoFocus; public static event Action OnRequestCancel; public static event Func OnRequestIsTorchOn; - + public static bool RequestIsTorchOn() { var evt = OnRequestIsTorchOn; return evt != null && evt(); } - public static void RequestTorch(bool on) + public static void RequestTorch(bool on) { var evt = OnRequestTorch; if (evt != null) @@ -106,7 +106,16 @@ protected override void OnNavigatedTo(NavigationEventArgs e) protected override void OnNavigatingFrom(NavigatingCancelEventArgs e) { - try { scannerControl.StopScanning(); } + try + { + OnRequestAutoFocus = null; + OnRequestTorch = null; + OnRequestToggleTorch = null; + OnRequestCancel = null; + OnRequestIsTorchOn = null; + + scannerControl.StopScanning(); + } catch (Exception ex) { } base.OnNavigatingFrom(e); diff --git a/src/ZXing.Net.Mobile/WindowsPhone/ZXingScannerControl.xaml.cs b/src/ZXing.Net.Mobile/WindowsPhone/ZXingScannerControl.xaml.cs index 3fc1d47f1..467175c46 100644 --- a/src/ZXing.Net.Mobile/WindowsPhone/ZXingScannerControl.xaml.cs +++ b/src/ZXing.Net.Mobile/WindowsPhone/ZXingScannerControl.xaml.cs @@ -92,6 +92,7 @@ public void AutoFocus() public void StopScanning() { + gridCustomOverlay.Children.Remove(CustomOverlay); _reader.Stop(); _reader = null; } From 616f5df41fe2763e7bb97e76996993a519ea7fa7 Mon Sep 17 00:00:00 2001 From: "Juan J. Chiw" Date: Wed, 9 Apr 2014 13:11:40 +0200 Subject: [PATCH 2/2] Bugfixes for windows phone user control and sample --- Samples/WindowsPhone7.1/WindowsPhone.Sample.sln | 16 ++++++++++------ .../WindowsPhone.Sample.csproj | 11 +++++------ .../WindowsPhone.Sample/packages.config | 1 + .../ZXing.Net.Mobile.WindowsPhone7.1.csproj | 8 ++++---- src/ZXing.Net.Mobile/packages.config | 2 +- 5 files changed, 21 insertions(+), 17 deletions(-) diff --git a/Samples/WindowsPhone7.1/WindowsPhone.Sample.sln b/Samples/WindowsPhone7.1/WindowsPhone.Sample.sln index ad78553d2..8665c532f 100644 --- a/Samples/WindowsPhone7.1/WindowsPhone.Sample.sln +++ b/Samples/WindowsPhone7.1/WindowsPhone.Sample.sln @@ -1,11 +1,11 @@  Microsoft Visual Studio Solution File, Format Version 12.00 -# Visual Studio 2012 +# Visual Studio Express 2012 for Windows Phone Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "WindowsPhone.Sample", "WindowsPhone.Sample\WindowsPhone.Sample.csproj", "{BC6808C6-5CEF-4D29-A23B-D2155334243D}" EndProject Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "zxing.wp7.1", "..\..\src\ZXing.Net\zxing.wp7.1.csproj", "{EC6F52B8-AF75-4FA2-85C1-82BF77861FFF}" EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ZXing.Net.Mobile.WindowsPhone7", "..\..\src\ZXing.Net.Mobile\ZXing.Net.Mobile.WindowsPhone7.csproj", "{CD15825D-D4CC-4BC4-9163-9CFB460AF836}" +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ZXing.Net.Mobile.WindowsPhone7.1", "..\..\src\ZXing.Net.Mobile\ZXing.Net.Mobile.WindowsPhone7.1.csproj", "{CD15825D-D4CC-4BC4-9163-9CFB460AF836}" EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution @@ -37,12 +37,16 @@ Global {EC6F52B8-AF75-4FA2-85C1-82BF77861FFF}.Release|x86.ActiveCfg = Release|Any CPU {CD15825D-D4CC-4BC4-9163-9CFB460AF836}.Debug|Any CPU.ActiveCfg = Debug|Any CPU {CD15825D-D4CC-4BC4-9163-9CFB460AF836}.Debug|Any CPU.Build.0 = Debug|Any CPU - {CD15825D-D4CC-4BC4-9163-9CFB460AF836}.Debug|ARM.ActiveCfg = Debug|Any CPU - {CD15825D-D4CC-4BC4-9163-9CFB460AF836}.Debug|x86.ActiveCfg = Debug|Any CPU + {CD15825D-D4CC-4BC4-9163-9CFB460AF836}.Debug|ARM.ActiveCfg = Debug|ARM + {CD15825D-D4CC-4BC4-9163-9CFB460AF836}.Debug|ARM.Build.0 = Debug|ARM + {CD15825D-D4CC-4BC4-9163-9CFB460AF836}.Debug|x86.ActiveCfg = Debug|x86 + {CD15825D-D4CC-4BC4-9163-9CFB460AF836}.Debug|x86.Build.0 = Debug|x86 {CD15825D-D4CC-4BC4-9163-9CFB460AF836}.Release|Any CPU.ActiveCfg = Release|Any CPU {CD15825D-D4CC-4BC4-9163-9CFB460AF836}.Release|Any CPU.Build.0 = Release|Any CPU - {CD15825D-D4CC-4BC4-9163-9CFB460AF836}.Release|ARM.ActiveCfg = Release|Any CPU - {CD15825D-D4CC-4BC4-9163-9CFB460AF836}.Release|x86.ActiveCfg = Release|Any CPU + {CD15825D-D4CC-4BC4-9163-9CFB460AF836}.Release|ARM.ActiveCfg = Release|ARM + {CD15825D-D4CC-4BC4-9163-9CFB460AF836}.Release|ARM.Build.0 = Release|ARM + {CD15825D-D4CC-4BC4-9163-9CFB460AF836}.Release|x86.ActiveCfg = Release|x86 + {CD15825D-D4CC-4BC4-9163-9CFB460AF836}.Release|x86.Build.0 = Release|x86 EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE diff --git a/Samples/WindowsPhone7.1/WindowsPhone.Sample/WindowsPhone.Sample.csproj b/Samples/WindowsPhone7.1/WindowsPhone.Sample/WindowsPhone.Sample.csproj index 34f880601..bce1fb463 100644 --- a/Samples/WindowsPhone7.1/WindowsPhone.Sample/WindowsPhone.Sample.csproj +++ b/Samples/WindowsPhone7.1/WindowsPhone.Sample/WindowsPhone.Sample.csproj @@ -52,7 +52,7 @@ False - .\System.Threading.Tasks.WP71.dll + ..\packages\System.Threading.Tasks.3.0.1\lib\sl4-wp71\System.Threading.Tasks.WP71.dll @@ -61,7 +61,10 @@ - .\WriteableBitmapExWinPhone.dll + ..\packages\WriteableBitmapEx.1.0.12.0\lib\sl4-wp71\WriteableBitmapExWinPhone.dll + + + ..\packages\WriteableBitmapEx.1.0.12.0\lib\sl4-wp71\WriteableBitmapExWinPhoneXnaDependant.dll @@ -98,10 +101,6 @@ - - {CD15825D-D4CC-4BC4-9163-9CFB460AF836} - ZXing.Net.Mobile.WindowsPhone7 - {EC6F52B8-AF75-4FA2-85C1-82BF77861FFF} zxing.wp7.1 diff --git a/Samples/WindowsPhone7.1/WindowsPhone.Sample/packages.config b/Samples/WindowsPhone7.1/WindowsPhone.Sample/packages.config index ff6ff3052..ad58c285a 100644 --- a/Samples/WindowsPhone7.1/WindowsPhone.Sample/packages.config +++ b/Samples/WindowsPhone7.1/WindowsPhone.Sample/packages.config @@ -1,4 +1,5 @@  + \ No newline at end of file diff --git a/src/ZXing.Net.Mobile/ZXing.Net.Mobile.WindowsPhone7.1.csproj b/src/ZXing.Net.Mobile/ZXing.Net.Mobile.WindowsPhone7.1.csproj index 8660f9aea..f5822122d 100644 --- a/src/ZXing.Net.Mobile/ZXing.Net.Mobile.WindowsPhone7.1.csproj +++ b/src/ZXing.Net.Mobile/ZXing.Net.Mobile.WindowsPhone7.1.csproj @@ -92,7 +92,7 @@ False - ..\packages\System.Threading.Tasks.3.0.1\lib\sl4-wp71\System.Threading.Tasks.WP71.dll + ..\..\Samples\WindowsPhone7.1\packages\System.Threading.Tasks.3.0.1\lib\sl4-wp71\System.Threading.Tasks.WP71.dll WindowsPhone\WriteableBitmapExWinPhone.dll @@ -138,15 +138,15 @@ Designer - - - {EC6F52B8-AF75-4FA2-85C1-82BF77861FFF} zxing.wp7.1 + + + diff --git a/src/ZXing.Net.Mobile/packages.config b/src/ZXing.Net.Mobile/packages.config index ff6ff3052..439785493 100644 --- a/src/ZXing.Net.Mobile/packages.config +++ b/src/ZXing.Net.Mobile/packages.config @@ -1,4 +1,4 @@  - + \ No newline at end of file