[Version 2.0] Change Theme

Oct 20, 2012 at 10:57 PM

How do you change the theme programmatically.

dockManager.Theme= new AeroTheme();

but I get the following error

Null Reference Exception

Object reference not set to an instance of an object.

 

Any help would be welcomed.

Oct 24, 2012 at 8:41 PM
Edited Oct 24, 2012 at 8:42 PM

The prevered way in AvalonDock [2.0] is to bind the Theme attached property of the DockManager to a viewmodel and then switch that property in the viewmodel. So, instead of setting it as you do you should be switching the content of a Workspace property

 

    private Theme _AvalonDockTheme = new AeroTheme();
    public Theme AvalonDockTheme
    {
      get
      {
        return this._AvalonDockTheme;
      }

      set
      {
        if (this._AvalonDockTheme != value)
        {
          this._AvalonDockTheme = value;
          this.NotifyPropertyChanged(() => this._AvalonDockTheme);
        }
      }
    }

 

and bind that in XAML:

    <avalonDock:DockingManager x:Name="dockManager" 
                               AnchorablesSource="{Binding Tools}" 
                               DocumentsSource="{Binding Files}"
                               ActiveContent="{Binding ActiveDocument, Mode=TwoWay, Converter={StaticResource ActiveDocumentConverter}}"
                               AllowDrop="True" Theme="{Binding AvalonDockTheme}">

I had this working before so there is a good chance that it works. But I had to style other items as well so I change the theme by changing/merging the resource dictionaries as it is the standard in WPF. I have published a new app based on AvalonDock [2.0] - please have a look at it: https://edi.codeplex.com/