RestoreLayout and custom DockablePane styles

Feb 7, 2011 at 10:40 PM
Edited Feb 7, 2011 at 10:43 PM

I have two dockable panes.  Pane1 has a custom style associated with it, and Pane2 uses the default style:


                    <ad:DockablePane Name="Pane1" Style="{DynamicResource ColorfulDockablePane}">
                        <ad:DockableContent Title="Pane1" Name="Pane1Content">                        	

                    <ad:DockablePane Name="Pane2" ad:ResizingPanel.ResizeHeight="200">
                        <ad:DockableContent Title="Pane2" Name="Pane2Content">


When I run the application, both panes look correct - Pane1 is rendered with the custom style.  However, after I call RestoreLayout, Pane1 then gets reset to the default style.  My question is, how do I set Pane1 to the custom style after RestoreLayout runs at runtime?  I have tried the following to no avail:


IsolatedStorageFileStream iStream = new IsolatedStorageFileStream("Layout.xml", FileMode.Open, iso);


//Pane1.Style = Pane2.Style;
Pane1.Style = (Style)FindResource("ColorfulDockablePane");

I also tried setting Pane1's style to Pane2's style before setting Pane1's style to the ColorfulDockablePane style, but that did not work either.  It looks like Pane1's style is programatically set to ColorfulDockablePane after RestoreLayout, but it does not render using that style after RestoreLayout runs.

Feb 10, 2011 at 7:31 PM

Can anyone shed some light on this issue?  I cannot figure this out!

Feb 15, 2011 at 7:40 PM
Edited Feb 15, 2011 at 7:41 PM

After a lot of debugging of AvalonDock's code, I discovered that after you call the RestoreLayout method, you are no longer able to access any panels or panes by name anymore.  This is because the RestoreLayout method actually orphans the original panels and panes in your XAML and replaces them with new ones that it creates.  This also means you are not able to use any styles for inherited classes.  Triggers in your original style will not work either, even on attached properties or dependency properties (with the exception of HasSingleItem!).

For instance you can't do this:

public class SpecialColoredDockablePane: DockablePane { }


<Style x:Key="{x:Type my:ColorfulDockablePane}" TargetType="{x:Type my:ColorfulDockablePane}">


The workaround is that you must set the style after RestoreLayout manually by walking the DockManager's tree, like this:


public dockManager.DockableContents.First(d => d.Name == "Pane1Content").ContainerPane.Style = (Style)FindResource("ColorfulDockablePane");