How to place instance of window in LayoutAnchorable AvalonDock 2

别等时光非礼了梦想. 提交于 2019-12-02 01:03:46

问题


I'm upgrading AvalonDock in a WPF C# application (not MVVM) from 1.3 to 2.0. In 1.3 I was able to place custom windows as long as used DockableContent: XAML:

<!--<Window-->
<ad:DockableContent   x:Class="Test.JournalWindow"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        xmlns:ad="clr-namespace:AvalonDock;assembly=AvalonDock" 
        xmlns:local="clr-namespace:Test"
        xmlns:sys="clr-namespace:System;assembly=mscorlib"

        Loaded="Journal_Loaded" StateChanged="Journal_StateChanged"
        Title="Journal" Icon = "Resources/journalLog.ico" HideOnClose="True" Height="300" Width="Auto">

    <ad:DockableContent.Resources>
      </ad:DockableContent.Resources>

                <Grid>  </Grid>
</ad:DockableContent>
<!--</Window>-->

Code Behind:

public partial class JournalWindow : DockableContent
    {
        public JournalWindow()
        {
            InitializeComponent();
        }

Code in MainWindow to display instantited element:

JournalWindow journalWindow;
 journalWindow = new JournalWindow()
            {
                Name = nameJournalWindow,
                Title = "Journal"
            };

            journalWindow.IsCloseable = true;
            journalWindow.HideOnClose = true;
            journalWindow.Show(dockManager);

How to place and show instance of JournalWindow in LayoutAnchorable or other layout element (previously as DockableContent) using AvalonDock 2 ?


回答1:


AvalonDock is changed a lot with new version. In AD 2.0 you have two option: 1) The simplest one is to create a standard UserControl (in your case JournalWindow derived from UserControl instead of DockableContent) and put the control inside the LayoutAnchorable (as its Content). Sample code:

<UserControl x:Class="Test.JournalWindow" ...>
...
</UserControl>

<LayoutAnchorable Title="My Journal Window">
   <testNamespace:JournalWindow/>
</LayoutAnchorable>

2) The recommended one is to use a MVVM approach and for this I'd point you to the sample project MVVMTestApp attached to AvalonDock library: http://avalondock.codeplex.com/downloads/get/558780

Ado



来源:https://stackoverflow.com/questions/13826634/how-to-place-instance-of-window-in-layoutanchorable-avalondock-2

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!