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

  • Home
  • SEARCH
  • 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 3965550
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T03:28:45+00:00 2026-05-20T03:28:45+00:00

I have a really nasty problem with bindings. I know that there are other

  • 0

I have a really nasty problem with bindings. I know that there are other topics regarding binding itmes inside itemtemplate to datacontext of an object outside the template. However, this just won’t work, i.e. the first textblock display ‘Test’ as desired whereas the same textbox inside the itemtemplate shows nothing.

  <TextBlock Text="{Binding DataContext.Test, ElementName=myList}"/>
  <ItemsControl x:Name="myList" ItemsSource="{Binding AllItems}"
                Margin="0,0,0,0" VerticalAlignment="Top" HorizontalAlignment="Center">
       <ItemsControl.ItemsPanel>
           <ItemsPanelTemplate>
                <toolkit:WrapPanel Orientation="Horizontal"                                    
                                           ItemHeight="170" ItemWidth="140"/>
           </ItemsPanelTemplate>
       </ItemsControl.ItemsPanel>
       <ItemsControl.ItemTemplate>
           <DataTemplate>
              <StackPanel>
                 <Image x:Name="{Binding KeyName}"
                        Source="{Binding ImagePath}"
                        Width="128"
                        Height="128">
                 </Image>

                 <TextBlock Text="{Binding DataContext.Test, ElementName=myList}"/>
                        </StackPanel>
            </DataTemplate>
        </ItemsControl.ItemTemplate>
    </ItemsControl>

I would appreciate some help here folks as this is really a problem for me.

  • 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-20T03:28:46+00:00Added an answer on May 20, 2026 at 3:28 am

    Inside the itemtemplate, the binding is initialized to the context of the current item in AllItems.

    Update

    Outside of the ItemTemplateyour bindings are relative to the DataContext of the page.**

    Once inside an ItemTemplate then bindings are limited to the scope of the item specifically being evaluated at that time.

    So, if we assume the following (based on the code in your question):

    <ItemsControl x:Name="myList" ItemsSource="{Binding AllItems}" >
        <ItemsControl.ItemTemplate>
             <DataTemplate>
                 <StackPanel>
                     <TextBlock x:Name="tb1"
                            Text="{Binding DataContext.Test, ElementName=myList}"/>
                     <TextBlock x:Name="tb2" Text="{Binding KeyName}"/>
                 </StackPanel>
             </DataTemplate>
         </ItemsControl.ItemTemplate>
     </ItemsControl>
    

    tb1 cannot access the DataContext object directly.
    tb2 cann access KeyName – assuming that whatever object AllItems is an IEnumerable of contains a property with that name.

    As I understand it, inside an itemtemplate, the item past from the enumeration controls the binding source and this can’t be overridden (by setting ElementName or otherwise).

    If you need the value from Test in every object in your enumeration then you’ll need to add it as a property of the object in the enumeration.

    I’m sure someone more knowledgeable than me could explain why this is or give a better explanation but that’s the gist of it.

    ** Assuming no other nesting of ItemsControls (or equivalent)

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

Sidebar

Related Questions

I'm having a really nasty problem with some code that I've written. I found
I really have a problem, I have a VS 2010 solution and it suddenly
I seem to be running into something really nasty: I have a form which
I have read about this function didReceiveMemoryWarning that actually hasn't really helped. I would
I have an iOS app with a really nasty bug: an operation in my
I have a nasty little problem with the pointer opperator in php (&). I
I have really big Oracle table with many columns that are not relevant to
I have really basic question. How can I get form id by input element
I have really no idea why I'm asking this as this a really completely
Im new to iPhone development and I have really taken this to me. I

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.