Example #1
0
        /// <inheritdoc />
        public override void Initialize(IConfig config)
        {
            // Prepare disposables
            _disposables?.Dispose();
            _disposables = new CompositeDisposable();

            AvailableThemes.Clear();
            foreach (var theme in MetroThemeManager.AvailableThemes)
            {
                AvailableThemes.Add(theme);
            }
            foreach (var themeColor in MetroThemeManager.AvailableThemeColors)
            {
                AvailableThemeColors.Add(themeColor);
            }

            // Place this under the Ui parent
            ParentId = "Ui";

            // Make sure Commit/Rollback is called on the UiConfiguration
            config.Register(MetroConfiguration);

            // automatically update the DisplayName
            _disposables.Add(UiTranslations.CreateDisplayNameBinding(this, nameof(IUiTranslations.Theme)));

            // Automatically show theme changes
            _disposables.Add(
                MetroConfiguration.OnPropertyChanging(nameof(MetroConfiguration.Theme)).Subscribe(args =>
            {
                if (args is PropertyChangingEventArgsEx propertyChangingEventArgsEx)
                {
                    _metroThemeManager.ChangeTheme(propertyChangingEventArgsEx.NewValue as string, null);
                }
            })
                );
            _disposables.Add(
                MetroConfiguration.OnPropertyChanging(nameof(MetroConfiguration.ThemeColor)).Subscribe(args =>
            {
                if (args is PropertyChangingEventArgsEx propertyChangingEventArgsEx)
                {
                    _metroThemeManager.ChangeTheme(null, propertyChangingEventArgsEx.NewValue as string);
                }
            })
                );
            base.Initialize(config);
        }