Ejemplo n.º 1
0
        /// <summary>
        /// Spawns a new virtual macro board with a given <paramref name="keyLayout"/>.
        /// </summary>
        /// <param name="keyLayout"></param>
        /// <returns></returns>
        public static IMacroBoard SpawnVirtualBoard(IKeyPositionCollection keyLayout)
        {
            VirtualBoardViewModel boardViewModel     = null;
            VirtualBoardWindow    boardWindow        = null;
            Exception             exceptionWasThrown = null;

            using (var waitForBoardWindow = new ManualResetEvent(false))
            {
                var uiThread = new Thread(() =>
                {
                    try
                    {
                        boardViewModel = new VirtualBoardViewModel(keyLayout);
                        boardWindow    = new VirtualBoardWindow(boardViewModel);
                    }
                    catch (Exception ex)
                    {
                        exceptionWasThrown = ex;
                        return;
                    }
                    finally
                    {
                        waitForBoardWindow.Set();
                    }

                    boardWindow.Show();
                    Dispatcher.Run();
                })
                {
                    IsBackground = true
                };

                uiThread.SetApartmentState(ApartmentState.STA);
                uiThread.Start();

                waitForBoardWindow.WaitOne();

                if (exceptionWasThrown != null)
                {
                    throw exceptionWasThrown;
                }

                return(boardViewModel);
            }
        }
Ejemplo n.º 2
0
        private void UpdateModelProperty()
        {
            var newModel = DataContext as VirtualBoardViewModel;

            if (ReferenceEquals(newModel, model))
            {
                return;
            }

            if (!(model is null))
            {
                model.PropertyChanged -= Model_PropertyChanged;
            }

            if (!(newModel is null))
            {
                newModel.PropertyChanged += Model_PropertyChanged;
            }

            model = newModel;
        }
Ejemplo n.º 3
0
 /// <summary>
 /// Creates an instance of <see cref="VirtualBoardWindow"/>.
 /// </summary>
 /// <param name="viewModel"></param>
 internal VirtualBoardWindow(VirtualBoardViewModel viewModel)
 {
     InitializeComponent();
     this.DataContext = viewModel;
 }