private void Edit(LinkedCommand command)
        {
            if (command == null)
            {
                return;
            }

            var dialog = new WpfCommandDialog(command, PageModel.Commands);

            dialog.ShowDialog();
        }
Exemplo n.º 2
0
        public WpfCommandDialog(LinkedCommand command, Commands allCommands)
        {
            InitializeComponent();

            _timer = new Timer {
                Interval = 200
            };
            _timer.Tick += OnTick;

            ThreadHelper.ThrowIfNotOnUIThread();
            Command  = command;
            Commands = from Command c in allCommands
                       where !string.IsNullOrEmpty(c.Name)
                       orderby c.Name
                       select c;

            before.IsChecked = command.ExecutionTime == ExecutionTime.Before;
            after.IsChecked  = command.ExecutionTime == ExecutionTime.After;

            Loaded += (s, e) =>
            {
                //reset the filter (without updating the view because the selected
                //item would scroll out of view again once the timer expires)
                search.TextChanged -= OnTextChanged;
                search.Text         = string.Empty;
                search.TextChanged += OnTextChanged;

                //refresh the view as it is still only displaying the last filtered result
                if (View != null)
                {
                    View.Refresh();
                }

                //select the currently attached command
                try
                {
                    ThreadHelper.ThrowIfNotOnUIThread();

                    var selected = allCommands.Item(command.Guid, command.Id);
                    if (selected == null)
                    {
                        return;
                    }
                    commands.SelectedItem = selected;
                    commands.ScrollIntoView(selected);
                }
                catch (ArgumentException)
                {
                }
            };
        }