void ActiveItemChanged(object x) { lock (ScreenHistory) { //var goingBack = ScreenIndex < ScreenHistory.Count() - 1; if (_goingBack || _goingForward) { _goingBack = false; _goingForward = false; } else { var newIndex = ScreenIndex + 1; var toRemove = ScreenHistory.Count() - newIndex; if (toRemove > 0) { ScreenHistory.RemoveRange(newIndex, toRemove); } ScreenHistory.Add(x); ScreenIndex = newIndex; } } }
protected override void OnInitialize() { using (this.Bench()) { base.OnInitialize(); this.WhenAnyValue(x => x.Connect.IsEnabled) .Select(x => x ? DefaultContactListWidth : 0).BindTo(this, x => x.ContactListWidth); // Workaround for screens.. object previous = null; this.WhenAnyObservable(x => x.Router.CurrentViewModel) .Subscribe(x => { var deactivatable = previous as IDeactivate; if (deactivatable != null) { deactivatable.Deactivate(false); } var activable = x as IScreen; if (activable != null) { activable.Activate(); } previous = x; }); this.WhenAnyObservable(x => x.Router.CurrentViewModel) .Select(x => x as IHaveOverlay) .BindTo(this, x => x.HasOverlay); this.WhenAnyValue(x => x.HasOverlay.Overlay) .BindTo(this, x => x.SubOverlay); var dm = Common.Flags.Verbose ? " (diagnostics mode)" : null; _systemInfo.WhenAnyValue(x => x.IsInternetAvailable) .Select(x => (x ? "Ready" : "Offline") + dm) .BindTo(this, x => x.ConnectionStatus); this.WhenAnyValue(x => x.UserSettings.AppOptions.AutoAdjustLibraryViewType, x => x.Width, x => x.WindowState, x => x.Connect.IsEnabled, (w, x, y, z) => w) .Where(x => x) .Subscribe(x => UpdateGridMode()); InitialWindowHandling(); this.WhenAnyValue(x => x.Content.ActiveItem) .Subscribe(ActiveItemChanged); this.WhenAnyValue(x => x.Home.CanGoBack, x => x.Home.CanGoForward, x => x.ScreenHistory.Count, x => x.ScreenIndex, x => x.Content.ActiveItem, (b, f, c, i, m) => new { CanGoBack = (c > 1 && i > 0) || (m == Home && Home.CanGoBack), CanGoForward = (c > 1 && i < ScreenHistory.Count() - 1) || (m == Home && Home.CanGoForward) }).Subscribe(x => { CanGoBack = x.CanGoBack; CanGoForward = x.CanGoForward; }); Overlay.ConductWith(this); Overlay.Parent = this; Connect.ConductWith(this); Connect.Parent = this; Router.Navigate.Execute(Content); } }