Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
196 views
in Technique[技术] by (71.8m points)

c# - AvalonDock DockingManager ActiveContent does not update

In my AvalonDock DockingManager the Property ActiveContent does not update the active tab when I load a new document. I have a ActiveDocument Property like this:

     private DocumentViewModel m_activeDocument;

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

I have an OnPropertyChanged Method like this:

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

I have an observable collection Documents like this:

    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;
        }
    }

and I call the dockingmanager like this:

    <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}}"
                       >

When I set the ActiveDocument to the just loaded documents like this:

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

the document does not show up in front.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

I forgot to derive the class from INotifyPropertyChanged:

class DXFViewerViewModel:INotifyPropertyChanged

Now it works.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...