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 6373959
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T01:25:45+00:00 2026-05-25T01:25:45+00:00

I have a MVVM application and somewhere in the application our company use a

  • 0

I have a MVVM application and somewhere in the application our company use a Third-Party that cannot use {Binding}. It’s a component that draw shapes, etc. What I want it, when the ViewModel load from the persisted storage all shapes to notify the View to draw them. In a perfect world I would just have the take the Third-party and bind it to the ViewModel Shapes collection but I cannot.

From there, my idea was that I could get from the View the ViewModel (via the DataContext) and to hook the PropertyChanged event. The problem is that the DataContext is not yet initialized in the constructor, so it’s NULL, and I cannot hook the event. Here is a sample of the code:

        public CanvasView()
        {
            InitializeComponent();
            ((CanvasViewModel)this.DataContext).PropertyChanged += new PropertyChangedEventHandler(CanvasView_PropertyChanged); //Exception Throw here because DataContext is null
        }

        void CanvasView_PropertyChanged(object sender, PropertyChangedEventArgs e)
        {
            if (e.PropertyName == "Shapes")
            {
                DrawShapes(); 
            }
        }

How can I get information from my ViewModel to my View in that case?

  • 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-05-25T01:25:46+00:00Added an answer on May 25, 2026 at 1:25 am

    All of the answers so far breaks the MVVM pattern with having code-behind on the view. Personally I would wrap the 3rd party control in a UserControl and then wire up a few dependency properties with property change events.

    C#

    public partial class MyWrappedControl : UserControl
    {
      public static readonly DependencyProperty ShapesProperty = DependencyProperty.Register("Shapes", typeof(ObservableCollection<IShape>), typeof(MyWrappedControl),
          new PropertyMetadata(null, MyWrappedControl.OnShapesPropertyChanged);
    
      public ObservableCollection<IShape> Shapes
      {
        get { return (ObservableCollection<IShape>)GetValue(ShapesProperty); }
        set { SetValue(ShapesProperty, value); }
      }
    
      private static void OnShapesPropertyChanged(DependencyObject o, DependencyPropertyChangedEventArgs e)
      {
        ((MyWrappedControl)o).OnShapesPropertyChanged(e);
      }
    
      private void OnShapesPropertyChanged(DependencyPropertyChangedEventArgs e)
      {
        // Do stuff, e.g. shapeDrawer.DrawShapes(); 
      }
    }
    

    XAML

    <UserControl 
        Name="MyWrappedControl"
        x:Class="MyWrappedControl"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation">
        <!-- your control -->
        <shapeDrawerControl x:Name="shapeDrawer" />
    </UserControl>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a MVVM application that contains multiple views with some complex IsReadOnly rules
I have an MVVM Silverlight 4 application that holds a list of modules (a
I am creating an application using the MVVM pattern and somewhere I have a
I have a MVVM application in WPF. I have an event that gets dispatched
I have a silverlight mvvm application that loads main view with 2 user controls
I have a wpf-mvvm application. In that I have follwoing... <Combo box> item 1
I have an MVVM kiosk application that I need to restart when it has
I have a MVVM application that has a slider bar and when the user
I have created WPF MVVM application, and set WPFToolkit DataGrid binding to DataTable so
I'm creating a WPF MVVM application. I have a long process that I want

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.