Exemple #1
0
        public override void SetDataContext(TestCompanyVm dataContext)
        {
            base.SetDataContext(dataContext);

            _tabControl.ItemsSource = dataContext.Employees;
            var selectionBinding = new TwoWayBinding(dataContext, nameof(TestCompanyVm.SelectedEmployee),
                                                     _tabControl, nameof(TabControl <EmployeeViewModel> .SelectedItem), null);

            _tabControl.AddBinding(selectionBinding);
            //UpdateSelection().ConfigureAwait(false);
        }
        internal MainWindowViewModel(Settings settings)
        {
            this.readOnlyEvents     = new ReadOnlyObservableCollection <Event>(this.events);
            this.consumerConnection = new ConnectionViewModel(this);
            this.providerConnection = new ConnectionViewModel(this);
            this.canEditSettings    = CalculatedProperty.Create(
                this.GetProperty(o => o.IsStarted),
                this.GetProperty(o => o.IsStopped),
                (isStarted, isStopped) => !isStarted && isStopped,
                this.GetProperty(o => o.CanEditSettings));
            #region  CalculatedProperty2
            this.canStart = CalculatedProperty.Create(
                this.GetProperty(o => o.IsStarted),
                this.GetProperty(o => o.IsStopped),
                this.GetProperty(o => o.ListeningPort),
                this.GetProperty(o => o.ProviderPort),
                this.GetProperty(o => o.LogFolder),
                (isStarted, isStopped, lp, pp, lf) => !isStarted && isStopped && string.IsNullOrEmpty(ValidatePort(lp) + ValidatePort(pp) + ValidateFolder(lf)),
                this.GetProperty(o => o.CanStart));
            #endregion
            this.canStop = CalculatedProperty.Create(
                this.GetProperty(o => o.IsStopped), s => !s, this.GetProperty(o => o.CanStop));
            this.settings = settings;

            #region TwoWayBinding
            TwoWayBinding.Create(
                this.settings.GetProperty(o => o.ListeningPort), this.GetProperty(o => o.ListeningPort));
            TwoWayBinding.Create(
                this.settings.GetProperty(o => o.ProviderHostName), this.GetProperty(o => o.ProviderHostName));
            TwoWayBinding.Create(
                this.settings.GetProperty(o => o.ProviderPort), this.GetProperty(o => o.ProviderPort));
            TwoWayBinding.Create(
                this.settings.GetProperty(o => o.LogFolder), this.GetProperty(o => o.LogFolder));
            TwoWayBinding.Create(
                this.settings.GetProperty(o => o.AutoScrollToMostRecentEvent),
                a => a,
                this.GetProperty(o => o.AutoScrollToMostRecentEvent),
                a => a.GetValueOrDefault());
            #endregion

            this.AddValidationRule(this.GetProperty(o => o.ProviderPort), ValidatePort);
            this.AddValidationRule(this.GetProperty(o => o.ListeningPort), ValidatePort);
            this.AddValidationRule(this.GetProperty(o => o.LogFolder), ValidateFolder);
        }