首页 > 解决方案 > AvalonDock DockingManager ActiveContent 不更新

问题描述

在我的 AvalonDock DockingManager 中,当我加载新文档时,属性 ActiveContent 不会更新活动选项卡。我有一个这样的 ActiveDocument 属性:

     private DocumentViewModel m_activeDocument;

    public DocumentViewModel ActiveDocument
    {
        get { return m_activeDocument; }
        set
        {
            m_activeDocument = value;
            OnPropertyChanged("ActiveDocument");
        }
    }

我有一个这样的 OnPropertyChanged 方法:

    public event PropertyChangedEventHandler PropertyChanged;
    public void OnPropertyChanged(string propertyChanged)
    {
        PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyChanged));
    }

我有一个可观察的集合文档,如下所示:

    private ObservableCollection<DocumentViewModel> m_documents = new ObservableCollection<DocumentViewModel>();
    private ReadOnlyObservableCollection<DocumentViewModel> m_readonlyDocuments = null;
    public ReadOnlyObservableCollection<DocumentViewModel> Documents
    {
        get
        {
            if (m_readonlyDocuments == null)
                m_readonlyDocuments = new ReadOnlyObservableCollection<DocumentViewModel>(m_documents);
            return m_readonlyDocuments;
        }
    }

我这样称呼对接管理器:

    <xcad:DockingManager Grid.Row="2" 
                       AllowMixedOrientation="True"
                       BorderBrush="Black"
                       BorderThickness="1"
                       Theme="{Binding ElementName=_themeCombo, Path=SelectedItem.Tag}"
                       DocumentsSource="{Binding Documents}"
                       ActiveContent="{Binding ActiveDocument, Mode=TwoWay, Converter={StaticResource ActiveDocumentConverter}}"
                       >

当我将 ActiveDocument 设置为刚刚加载的文档时,如下所示:

            var ld = new DocumentViewModel { Title = fileName, PltModel = tmp };
            m_documents.Add(ld);
            ActiveDocument = ld;

文件没有出现在前面。

标签: c#.netwpfavalondock

解决方案


我忘了从 INotifyPropertyChanged 派生类:

class DXFViewerViewModel:INotifyPropertyChanged

现在它起作用了。


推荐阅读