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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T23:54:59+00:00 2026-06-08T23:54:59+00:00

For some reason I am unable to bind to ViewModel properties within DataTemplates on

  • 0

For some reason I am unable to bind to ViewModel properties within DataTemplates on some controls. The result of the binding itself is unpredictable, sometimes it work, sometimes it doesn’t. For this reason I am thinking of exposing the ViewModel in some other way besides setting it as DataContext.

First thought was to add ViewModel to Resources collection. I am using TabControls for UI, so whenever a view needs to be displayed, it is done through Data templates.

<DataTemplate DataType="{x:Type vm:SomeViewModel}">
    <vw:SomeView />
</DataTemplate>

In this situation the view is instantiated automatically, and its DataContext is set to ViewModel set in template. Is there a way I can make this ViewModel available to View’s Resources (ex with key=viewModel), so that I can use it like this:

<TextBlock Text="{Binding SomeProperty, Source={StaticResource viewModel}}" />

I have tried adding it in code, in the Loaded event for the View:

this.Loaded += (s, e) =>
{
    this.Resources.Add("viewModel", this.DataContext);
};

Above code is executed before the error pops up that says static resource is not found at run-time, so the resource was added to collection.

Any ideas what can I do?

  • 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-08T23:55:01+00:00Added an answer on June 8, 2026 at 11:55 pm

    You can define ViewModel as a resource in XAML like that:

    <vm:SomeViewModel x:Key="ViewModel"/>
    

    If you want to Bind to DataContext in a DataTemplate you can use the following:

    {Binding Path=DataContext, ElementName=uc}

    assuming that your window/usercontrol name is x:Name=”uc” , or as @stukselbax wrote:

    {Binding Path=DataContext, RelativeSource={RelativeSource Mode=FindAncestor, AncestorType=[UserControl|Window]}} 
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

For some reason I am unable to set and width properties of TD elements
I am unable to get my sessions captcha to work for some reason. This
for some reason I cannot get a foreach binding to work with a $data
I have good familiarity with CSS but for some reason I am unable to
I need something real simple, that for some reason I am unable to accomplish
For some reason im unable to solve this. what will be the Big-o Notation
For some reason Im unable to get the submit button below to re-enable once
For some reason i am unable to save HABTM relationships, I have checked the
For some reason I am unable to get the pattern match for preference_network_ followed
For some strange reason I am unable to add the canonical tag to opencart

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.