private void SetBinding(VIEW view)
        {
            var dps = AppDialogService.GetDependencyProperties(view, false);

            foreach (var b in _propBindings)
            {
                string[] bdef = b.Split(',');
                var      dp   = dps.FirstOrDefault(d => d.Name == bdef[0]);
                if (dp != null)
                {
                    BindingOperations.SetBinding(view, dp, CreateBinding(bdef[1]));
                }
            }
        }
示例#2
0
        protected override void OnStartup(System.Windows.StartupEventArgs e)
        {
            DispatcherUnhandledException += Application_DispatcherUnhandledException;

            // Call the OnStartup event on our base class
            base.OnStartup(e);

            var v = this.GetType().Assembly.GetName().Version;

            string preproduction = " ?";

            if (v.Build == 0)
            {
                preproduction = "";
            }
            else if (v.Build % 2 != 0)
            {
                preproduction = " αlpha" + (v.Build + 1) / 2 + " (rev." + v.Revision + ")";
            }
            else if (v.Build % 2 == 0)
            {
                preproduction = " βeta" + v.Build / 2 + " (rev." + v.Revision + ")";
            }

            this.Properties["Version"]      = string.Format("v{0}.{1}{2}", v.Major, v.Minor, preproduction);
            this.Properties["VersionShort"] = string.Format("v{0}.{1}", v.Major, v.Minor);

            Exit += new ExitEventHandler(App_Exit);
            Thread preloader = new Thread(PreloadAssemblies);

            preloader.IsBackground = true;
            preloader.Priority     = ThreadPriority.BelowNormal;
            preloader.Start();

            this.Resources = Application.LoadComponent(new Uri("App.xaml", UriKind.RelativeOrAbsolute)) as ResourceDictionary;

            var w = new Window1();

            ServiceLocator.RegisterService <IMainView>(w);
            var dlgsrv = new AppDialogService();

            ServiceLocator.RegisterService <IDialogService>(dlgsrv);
            ServiceLocator.RegisterService <IMainWindow>(w);

            var vm = new Main {
                Themes = new ObservableCollection <ThemeInfo>(StyleLoader.GetAllStyles())
            };

            w.DataContext = vm;
            ServiceLocator.RegisterOverrideService <IKeyboardHandler>((IKeyboardHandler)vm);
            ServiceLocator.RegisterOverrideService <IActionExecutor>((IActionExecutor)vm);

            this.Resources.BeginInit();

            var sl         = new StyleLoader(Resources);
            var startTheme = new ThemeInfo {
                Path = "default"
            };

            startTheme = sl.LoadStyle(startTheme);
            StyleLoader.CurrentStyleFolder = startTheme.Path;
            vm.CurrentTheme = vm.Themes.FirstOrDefault(t => t.Path == startTheme.Path);

            //this.Resources.MergedDictionaries.Add(Application.LoadComponent(new Uri("/Themes/default/style.xaml", UriKind.RelativeOrAbsolute)) as ResourceDictionary);
            this.Resources.EndInit();

            sl.PerformInit = true;

            var b = new System.Windows.Controls.Button();

            ServiceLocator.RegisterService <IStyleLoader>(sl);
            ServiceLocator.RegisterService <IFramePictureProvider>(w);
            ServiceLocator.RegisterService <IInputTeller>(w);
            ServiceLocator.RegisterService <IPlateProcessor>(vm);
            ServiceLocator.RegisterService <ISettings>(vm);

            //sl.LoadStyle("default");

            string[] args = Environment.GetCommandLineArgs();
            if (args.Length > 1)
            {
                (MainWindow as Window1).StartupFile = args[1];
            }

            InterceptKeys.Start((MainWindow as Window1));

            w.Show();
        }