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 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 seem to be running into something really nasty: I have a form which
We have a legacy WSE3 ASP.Net webservice here that defines a method GetFileContent(string fileName)
I have a button used to delete a row when checked that calls the
I have a class that contains some data, and I would like to add
I have a class which serves as a model for an image: class Image
I just want to know if an object is in an array or not.
I found this nifty code snippet on several sites, allowing me to analyze the
I've been creating a temporary object stack- mainly for the use of heap-based STL
I am developing an MVC application which and I'm not clear on the ideal
My program requires access to a certain UNC path, but the path is cross-domain,

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.