internal RelayCommand(RelayCommandBindings relayCommandBindings)
 {
     this.relayCommandBindings = relayCommandBindings;
     relayCommandBindings.BindingModel.PropertyChanged += (s, e) =>
     {
         if (relayCommandBindings.BindingProperties.Any(p => p == e.PropertyName))
         {
             CanExecuteChanged?.Invoke(this, EventArgs.Empty);
         }
     };
 }
Ejemplo n.º 2
0
    public MultiplexViewModel()
    {
        multiPlexModel         = new MultiPlexModel();
        synchronizationContext = SynchronizationContext.Current;
        var bindingProperties = new[]
        {
            nameof(IsActive),
            nameof(IsActiveChanging)
        };
        var setNewNameBindings = new RelayCommandBindings()
        {
            Execute          = async(obj) => await multiPlexModel.StartMultiplexModelAsync(obj.ToString()),
            CanExecuteChecks = new List <Predicate <object> >
            {
                (obj) => IsValidName(obj?.ToString()),
                (obj) => IsActive == false,
                (obj) => IsActiveChanging == false
            },
            BindingModel      = this,
            BindingProperties = bindingProperties
        };
        var stopMultiplexBindings = new RelayCommandBindings()
        {
            Execute          = async(obj) => await multiPlexModel.StopMultiplexModelAsync(),
            CanExecuteChecks = new List <Predicate <object> >
            {
                (obj) => IsActive == true,
                (obj) => IsActiveChanging == false
            },
            BindingModel      = this,
            BindingProperties = bindingProperties
        };

        SetNewNameCommand               = new RelayCommand(setNewNameBindings);
        StopMultiplexCommand            = new RelayCommand(stopMultiplexBindings);
        multiPlexModel.PropertyChanged += (s, e) => GetType().GetProperties().Where(p => p.Name == e.PropertyName).FirstOrDefault()?.SetValue(this, multiPlexModel.GetType().GetProperty(e.PropertyName).GetValue(multiPlexModel));
    }