void barCodecontrol_Completed(object sender, string e)
        {
            Deployment.Current.Dispatcher.BeginInvoke(() =>
            {
                barCodecontrol.StopReadingBarcode();
                barCodecontrol.ReadComplete -= barCodecontrol_Completed;

                PhoneApplicationFrame frame = Application.Current.RootVisual as PhoneApplicationFrame;
                PhoneApplicationPage page = null;

                if (frame != null)
                {
                    page = frame.Content as PhoneApplicationPage;
                }

                if (page != null)
                {
                    Grid grid = page.FindName("LayoutRoot") as Grid;
                    if (grid != null)
                    {
                        page.OrientationChanged -= page_OrientationChanged;

                        grid.Children.Remove(barCodecontrol);
                        barCodecontrol = null;

                        // user hit back button
                        if (e == null)
                        {
                            string js = "var e=document.createEvent('Events');e.initEvent('intel.xdk.device.barcode.scan',true,true);e.success=false;e.codetype='';e.codedata='';document.dispatchEvent(e);";
                            InvokeCustomScript(new ScriptCallback("eval", new string[] { js }), true);
                        }
                        else
                        {
                            e = e.Replace(System.Environment.NewLine,"\\n");
                            string format = "QR_CODE";
                            string js = "var e=document.createEvent('Events');e.initEvent('intel.xdk.device.barcode.scan',true,true);e.success=true;e.codetype='" + format + "';e.codedata='" + e + "';document.dispatchEvent(e);";
                            InvokeCustomScript(new ScriptCallback("eval", new string[] { js }), true);
                        }
                    }
                }
                else
                {
                    string js = "var e=document.createEvent('Events');e.initEvent('intel.xdk.device.barcode.scan',true,true);e.success=false;e.codetype='';e.codedata='';document.dispatchEvent(e);";
                    InvokeCustomScript(new ScriptCallback("eval", new string[] { js }), true);
                }
            });
        }
        public void scanBarcode(string parameters)
        {
            Deployment.Current.Dispatcher.BeginInvoke(() =>
                {
                    if (page != null)
                    {
                        Grid grid = page.FindName("LayoutRoot") as Grid;
                        if (grid != null)
                        {
                            barCodecontrol = new BarCodeControl();

                            PageOrientation po = ((PhoneApplicationFrame)(Application.Current.RootVisual)).Orientation;
                            if (po == PageOrientation.Landscape || po == PageOrientation.LandscapeLeft || po == PageOrientation.LandscapeRight)
                            {
                                barCodecontrol.Height = Application.Current.Host.Content.ActualWidth;
                                barCodecontrol.Width = Application.Current.Host.Content.ActualHeight;
                            } else {
                                barCodecontrol.Height = Application.Current.Host.Content.ActualHeight;
                                barCodecontrol.Width = Application.Current.Host.Content.ActualWidth;
                            }
                            //barCodecontrol.viewFeed.Height = Application.Current.Host.Content.ActualHeight;
                            //barCodecontrol.viewFeed.Width = Application.Current.Host.Content.ActualWidth;

                            grid.Children.Add(barCodecontrol);

                            barCodecontrol.ReadComplete += barCodecontrol_Completed;
                        }
                    }
                    else
                    {
                    }
                });
        }