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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 19, 20262026-05-19T09:01:13+00:00 2026-05-19T09:01:13+00:00

I am using Mvvm-Light and have been ignoring how binding in XAML really works

  • 0

I am using Mvvm-Light and have been ignoring how binding in XAML really works up until now.

Here’s my XAML

<phone:PhoneApplicationPage.Resources>
</phone:PhoneApplicationPage.Resources>

<Grid x:Name="LayoutRoot" Background="Transparent">

    <StackPanel x:Name="TitlePanel" Grid.Row="0" Margin="12,17,0,14">
        <TextBlock x:Name="ApplicationTitle" Text="{Binding SecuritySystemName}" Style="{StaticResource PhoneTextNormalStyle}"/>
        <TextBlock x:Name="PageTitle" Text="{Binding PageName}" Margin="9,-7,0,0" Style="{StaticResource PhoneTextTitle1Style}"/>
    </StackPanel>

    <TextBlock Name="textCode" 
        DataContext="{WHAT GOES HERE to bind to properties on my View (SecurityPanelPage class)}"    
        Text="{Binding Path=Code}" />

</Grid>

{Binding SecuritySystemName} and {Binding PageName} correctly bind to my ViewModel (SecuirtyPanelViewModel). But I want {Binding Code} in the TextBlock element to bind to my VIEW (not ViewModel).

I have searched and searched for documentation & samples that explain the syntax and values supported by DataContext and Binding. Nothing has helped.

All I want to know is how do I set a DataContext (or specify something in a {Binding …} that will point to my View object. I’ve tried “Self” and all sorts of “RelativeSource” things, but none work. Guessing is not productive because the round trip into the debugger before the XAML is parsed is too long.

Thanks.

UPDATE – I found AN answer that gets me moving, but I still don’t grok so I have follow up questions for the fine posters below..

Here’s what works:

<phone:PhoneApplicationPage x:Name="ThisPage">
   <TextBlock Name="textCode" Text="{Binding Code, ElementName=ThisPage"/>
</phone:PhoneApplicationPage>

I found this hint here: http://bursjootech.blogspot.com/2007/12/bind-from-xaml-to-local-property-in.html

He asked the question differently: how to “Bind from XAML to a local property in code-behind”.

I still don’t understand the two solutions provided below. So more questions below…

  • 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-19T09:01:14+00:00Added an answer on May 19, 2026 at 9:01 am

    Typically when you’re using MVVM nearly all of your bindable properties are on your ViewModel and not on your Views. However, obviously sometimes you want to create component controls which do have properties. Can you explain what the property is and why it needs to only be a property on the view?

    That being said … I’m guessing your SecurityPanelPage is the view for the XAML displayed?

    You can give your control a name and then use ElementName binding. This way you do not need to set the DataContext.

    <phone:PhoneApplicationPage
      x:Name="controlName"
      x:Class="SomeNamespace.SecurityPanelPage">
    </phone:PhoneApplicationPage>
    

    And then your binding changes to:

    <TextBlock
      Name="textCode" 
      Text="{Binding Path=Code, ElementName=controlName}" />
    

    To explicitly set the DataContext you can do the following:

    <TextBlock
      Name="textCode" 
      DataContext="{Binding ElementName=controlName}"
      Text="{Binding Path=Code}" />
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have been trying to learn MVVM using Laurent Bugnion MVVM light method. I
I'm using the mvvm-light toolkit in my windows phone 7 application. I have in
I'm using MVVM Light to build a WP7 (Windows Phone 7) application. I wish
I'm using MVVM (MVVM Light Toolkit) and have a property on the view model
I have recently started using the MVVM-Light toolkit and I am stuck on the
Are there any gotchas using mvvm-light and the RTW windows phone 7 tools? There
I'm using MVVM Light toolkit (which I love). I currently have messaging in place
I'm writing a Silverlight app using the MVVM pattern. I have a main view
I have been looking into MVVM design patterns with WPF for a project. I
I am using MVVM Light toolkit in my WPF application. I would like to

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.