示例#1
0
 /// <summary>
 /// Observe the settings panel activation and adds command.
 /// </summary>
 /// <param name="observer"></param>
 /// <returns></returns>
 public IDisposable Subscribe(IObserver <Unit> observer)
 {
     return(Observable.Defer(() =>
     {
         var settingsPane = SettingsPane.GetForCurrentView();
         return Observable.FromEventPattern <TypedEventHandler <SettingsPane, SettingsPaneCommandsRequestedEventArgs>, SettingsPaneCommandsRequestedEventArgs>(
             h => settingsPane.CommandsRequested += h,
             h => settingsPane.CommandsRequested -= h,
             _dispatcher);
     })
            .Do(args =>
     {
         var settingsArgs = args.EventArgs;
         foreach (var commandDefinition in _commandDefinitions.Where(d => d.Command(_viewModel.Value).CanExecute(null)))
         {
             CommandDefinition definition = commandDefinition;
             settingsArgs.Request.ApplicationCommands.Add(new SettingsCommand(
                                                              commandDefinition.Id,
                                                              _resources.Get(commandDefinition.TitleKey),
                                                              command => definition.Command(_viewModel.Value).Execute(null)));
         }
     })
            .SelectUnit()
            .Subscribe(observer));
 }