Esempio n. 1
0
        /// <summary>
        /// Creates a SpaceRecordingView and attaches an instance of SpaceRecordingViewModel to it.
        /// </summary>
        /// <param name="selectedSpace">Space to record in.</param>
        /// <param name="project">The current LiveDescribe Project.</param>
        /// <returns>The ViewModel of the Window.</returns>
        public static SpaceRecordingViewModel SpawnSpaceRecordingView(Space selectedSpace, Project project)
        {
            var viewModel = new SpaceRecordingViewModel(selectedSpace, project);
            var view = new SpaceRecordingView(viewModel);
            viewModel.DialogResult = view.ShowDialog();

            return viewModel;
        }
        public SpaceRecordingView(SpaceRecordingViewModel vm)
        {
            InitializeComponent();

            _viewModel = vm;

            _viewModel.CloseRequested += (sender, args) =>
            {
                DialogResult = true;
                Close();
            };

            _viewModel.RecordingStarted += (sender, args) =>
            {
                SpaceTextBox.Focus();
                SpaceTextBox.IsReadOnly = true;
                _enumerator = _viewModel.SpaceTextTokenizer.Tokens.GetEnumerator();
            };

            _viewModel.RecordingEnded += (sender, args) =>
            {
                SpaceTextBox.Select(0, 0);
                SpaceTextBox.IsReadOnly = false;
            };

            _viewModel.NextWordSelected += (sender, args) =>
            {
                if (_enumerator.MoveNext())
                {
                    var token = _enumerator.Current;
                    SpaceTextBox.Select(token.StartIndex, token.Length);
                }
                else
                {
                    SpaceTextBox.Select(SpaceTextBox.Text.Length - 1, 0);
                }
            };

            DataContext = _viewModel;
        }