Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8142999
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T12:58:40+00:00 2026-06-06T12:58:40+00:00

I know that’s bad design, but I need access to the view from my

  • 0

I know that’s bad design, but I need access to the view from my viewmodel. This is because I have some old controls, e.g. Winforms controls, that don’t support binding and need to be filled by code.

I’m using the MVVM model of AvalonDock 2.0 and have something similar to this:

   <ad:DockingManager x:Name="dockManager" 
                  DocumentsSource="{Binding Files}"
                  AnchorablesSource="{Binding Tools}"
        ActiveContent="{Binding ActiveDocument, Mode=TwoWay, Converter={StaticResource ActiveDocumentConverter}}">
        <ad:DockingManager.LayoutItemTemplateSelector>
            <local:PanesTemplateSelector>
                <local:PanesTemplateSelector.NavigationViewTemplate>
                    <DataTemplate>
                        <tvext:TreeViewExtended />
                    </DataTemplate>
                </local:PanesTemplateSelector.NavigationViewTemplate>
            </local:PanesTemplateSelector>
        </ad:DockingManager.LayoutItemTemplateSelector>

So the template NavigationViewTemplate is bound to one item of the collection Tools, which is my ViewModel of type NavigationViewModel.

I have no problem binding e.g. a TextBox to a property of my viewmodel. But I don’t know how I can get access from my NavigationViewModel to the tvext:TreeViewExtended control inside the template in order to fill it.

TIA Michael

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-06T12:58:41+00:00Added an answer on June 6, 2026 at 12:58 pm

    I suggest that you do not access the Winforms control from your ViewModel. Keep everything that relates to the view in the view. You can do this as follows:

    1. Create a WPF custom control, e.g. named TreeViewExtendedWrapper. (See this article for a short tutorial how to create custom WPF controls).

    2. Inside the control template of the custom control (in the Themes\Generic.xaml file), place your Winforms control:

      <ControlTemplate TargetType="{x:Type local:TreeViewExtendedWrapper}">
          <Border Background="{TemplateBinding Background}"
              BorderBrush="{TemplateBinding BorderBrush}"
              BorderThickness="{TemplateBinding BorderThickness}">
              <tvext:TreeViewExtended />
          </Border>
      </ControlTemplate>
      
    3. Add dependency properties to your custom control for all Winforms control properties that you need to bind to the ViewModel.

    4. Also add dependency properties to your custom control for all commands that you need to bind to the view model.

    5. Write C# code inside the code-behind of the custom control to connect the dependency properties of your custom control to the properties, events, and methods of the Winforms control.

    6. Inside your data template, place your custom control with any necessary data bindings:

      <DataTemplate>
          <local:TreeViewExtendedWrapper MyProperty={Binding MyProperty}/> 
      </DataTemplate> 
      

    With this approach, you can use data binding to connect ViewModel and Winforms control, i.e. you do not violate MVVM principles.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I know that this question might have been asked like 100 times, but, believe
I know that this has already been asked here but the answer (using a
I know that design patterns is generally something that's connected to OO programming, but
I know that there are more than a dozen questions about this. But I
I know that this hasn't always been the case, so I have changed something
I know that I can get access to column properties via: select * from
I know that this Question is repeated but I can't find the answer in
I know that this may be common knowledge, but is there a way to
I know that I can use git commit --amend --file=path-to-my-new-message but this will amend
We know that IPhone has a push notification function. But I have different kinds

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.