Ejemplo n.º 1
0
 /// <summary>
 /// Executes the first command and then when it completes executes the second command.  Both commands
 /// expect TInput as a parameter.  The second command returns TOutput. The returned command expects
 /// TInput and returns TOutput when executed.
 /// </summary>
 /// <param name="first">The command to execute first</param>
 /// <param name="second">The command to execute second</param>
 /// <returns>The new command that executes both commands in turn.</returns>
 public static IRxFunction <TInput, TOutput> Combine <TInput, TOutput>(this IRxCommand <TInput> first, IRxFunction <TInput, TOutput> second)
 {
     return(RxFunction.CreateAsync <TInput, TOutput>(async x =>
     {
         await first.InvokeAsync(x);
         return await second.InvokeAsync(x);
     }));
 }
Ejemplo n.º 2
0
 /// <summary>
 /// Executes the first command and then when it completes executes the second command.  The second command
 /// expects TInput as an argument, and the returned command also expects TInput when executed.
 /// </summary>
 /// <param name="first">The command to execute first</param>
 /// <param name="second">The command to execute second</param>
 /// <returns>The new command that executes both commands in turn.</returns>
 public static IRxCommand <TInput> Combine <TInput>(this IRxCommand first, IRxCommand <TInput> second)
 {
     return(RxCommand.Create <TInput>(async x =>
     {
         await first.InvokeAsync();
         await second.InvokeAsync(x);
     }));
 }
Ejemplo n.º 3
0
 /// <summary>
 /// Executes the first command and then when it completes executes the second command.
 /// </summary>
 /// <param name="first">The command to execute first</param>
 /// <param name="second">The command to execute second</param>
 /// <returns>The new command that executes both commands in turn.</returns>
 public static IRxCommand Combine(this IRxCommand first, IRxCommand second)
 {
     return(RxCommand.Create(async() =>
     {
         await first.InvokeAsync();
         await second.InvokeAsync();
     }));
 }
Ejemplo n.º 4
0
        public MainWindow()
        {
            escape         = RxCommand.Create(EscapeImpl);
            ViewDispatcher = new MainWindowViewDispatcher(this);

            Title = "Craft";
            WindowStartupLocation = WindowStartupLocation.CenterScreen;

            InitializeComponent();

            ViewDispatcher.RegisterLast <MainWindowState>(SetState);
            // trigger ^ with anything set up already
            ViewDispatcher.Dispatch(ViewDispatcher.LastState);
        }
Ejemplo n.º 5
0
        public SelectManyDemoVm()
        {
            Items       = new ObservableCollection <ItemVm>().AllDisposedBy(this);
            SelectedIds = new ObservableCollection <string>  {
                "2", "5", "8", "1111", "11115", "22229", "StamItem"
            };
            Initialize();
            SelectionCommand  = MvvmRx.CreateCommand <IEnumerable <String> >(this);
            RandomFiveCommand = MvvmRx.CreateCommand(this);
            RemoveSelected    = MvvmRx.CreateCommand <IEnumerable>(this);
            ResetCommand      = MvvmRx.CreateCommand(this);
            ClearCommand      = MvvmRx.CreateCommand(this);

            SelectionCommand.Select(ienum => ienum.ToObservableCollection()).ApplyOnProperty(this, x => x.SelectedIds);
            RandomFiveCommand.Subscribe(_ =>
            {
                var rnd   = new Random();
                var items = Enumerable.Range(0, 5).Select(__ => Items[rnd.Next(Items.Count)].Uid);
                SelectedIds.AddRange(items);
            }).DisposedBy(this);

            RemoveSelected.Subscribe(x =>
            {
                foreach (var item in x.OfType <string>().ToArray())
                {
                    SelectedIds.Remove(item);
                }
            }).DisposedBy(this);

            ResetCommand.Subscribe(_ =>
            {
                var rnd     = new Random();
                var ids     = Items.Select(x => x.Uid).Where(x => rnd.Next(40) < 2).ToObservableCollection();
                SelectedIds = ids;
            }).DisposedBy(this);

            ClearCommand.Subscribe(_ =>
            {
                Items.Clear();
            }).DisposedBy(this);
        }
Ejemplo n.º 6
0
 public ViewModel()
 {
     Items      = new ObservableCollection <ItemVm>().AllDisposedBy(this);
     AddItem    = MvvmRx.CreateCommand(this);
     RemoveItem = MvvmRx.CreateCommand <string>(this);
 }
Ejemplo n.º 7
0
 /// <summary>
 /// Converts an unparameterized command into a command parameterized by Unit.  This can be useful with methods such
 /// as Combine which expect particular types of commands that may not fit the command you have in order to
 /// get the behavor you otherwise expect.
 /// </summary>
 public static IRxCommand <Unit> AsParameterized(this IRxCommand command)
 {
     return(RxCommand.Create <Unit>(_ => command.InvokeAsync()));
 }
Ejemplo n.º 8
0
 /// <summary>
 /// Executes the first command and then when it completes executes the second command.  The first command
 /// returns TOutput.  The returned command also returns TOutput.
 /// </summary>
 /// <param name="first">The command to execute first</param>
 /// <param name="second">The command to execute second</param>
 /// <returns>The new command that executes both commands in turn.</returns>
 public static IRxFunction <TOutput> Combine <TOutput>(this IRxFunction <TOutput> first, IRxCommand second)
 {
     return(RxFunction.CreateAsync(async() =>
     {
         var result = await first.InvokeAsync();
         await second.InvokeAsync();
         return result;
     }));
 }
Ejemplo n.º 9
0
 /// <summary>
 /// Executes the command synchronously by calling Wait() on the async task.  This should generally only be
 /// called when you know the action will execute synchronously.  Otherwise you will likely face potential
 /// deadlocks.
 /// </summary>
 public static void Invoke <TInput>(this IRxCommand <TInput> command, TInput input)
 {
     command.InvokeAsync(input).Wait();
 }
Ejemplo n.º 10
0
 /// <summary>
 /// Executes the command synchronously by calling Wait() on the async task.  This should generally only be
 /// called when you know the action will execute synchronously.  Otherwise you will likely face potential
 /// deadlocks.
 /// </summary>
 public static void Invoke(this IRxCommand command)
 {
     command.InvokeAsync().Wait();
 }
Ejemplo n.º 11
0
 public ItemVm()
 {
     DoMath = MvvmRx.CreateCommand <int>(this);
 }