简体   繁体   中英

How to bind my UserControl to an AvalonDock

please I am getting out of my mind trying to understand something, I really need some direction, because I am lost.

I have a UserControl I created called TerminalControl which have a view which wraps a TextBox bounded to a Text property in the view model, which is updated in real time through RS232 connected to an embedded system. So the flow is data arrives to RS232 (updates) ==> VM.Text ==> (data binding) ==> TerminalView.TextBox.Text

All I want is to add this user control to an AvalonDock 2.0 through data binding.

I created a data template in the window holding the Docking Manager

  <avalonDock:DockingManager x:Name="dockManager"                                
                               DocumentsSource="{Binding ???}"                                   
                               Grid.Row="1">        
    <avalonDock:DockingManager.LayoutItemTemplateSelector>
        <vm:PanesTemaplateSelector>
            <vm:PanesTemaplateSelector.SessiomDataTemplate >
                <DataTemplate>
                    <Terminal:TerminalEditorView/>
                </DataTemplate>
            </vm:PanesTemaplateSelector.SessiomDataTemplate>        
        </vm:PanesTemaplateSelector>
    </avalonDock:DockingManager.LayoutItemTemplateSelector>

and created the documents inside the docking

  <avalonDock:LayoutRoot>
        <avalonDock:LayoutPanel Orientation="Vertical">
            <avalonDock:LayoutDocumentPane/>
            <avalonDock:LayoutAnchorablePane Name="ToolsPane" DockHeight="150">
            </avalonDock:LayoutAnchorablePane>
        </avalonDock:LayoutPanel>
    </avalonDock:LayoutRoot>
</avalonDock:DockingManager>

I have a modul that creates a TerminalControl and returns the viewModel to the MainWin view model. My problem is that I dont know to what I should bind the DocumentSource of the AvalonDock, as you can see above.

What am I doing wrong? Is there something wrong in my architecture?

Guys, any help will be highly appriciated because I am running out of ideas.

Thanks

Ok, since there is no answer to my questiuon, here is the solution I am going on:

  • My UserControl (Terminal) will implement an interface IUIWindow.
  • This interface will be held by the main view model in an observebale collection, which will dynamically will add or remove IUIWindow elements.
  • and the the Avalon dock which resides in the main view will bind to that collection in its DocumentSource.
  • In the binding I will hold a converter which will convert from the interface to the type the Document expect.

This is the best solution I could find, if anyone has any opinions/remarks/suggestions I will be glad to hear.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM