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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T23:41:59+00:00 2026-05-31T23:41:59+00:00

while programming for windows phone 7, I created a listbox and using DataTemplate which

  • 0

while programming for windows phone 7, I created a listbox and using DataTemplate which contains a textblock and a textbox. The textbox is hided by default.

The XAML:

<ListBox>
        <ListBox.ItemTemplate>
            <DataTemplate>
                <Canvas Width="460" Height="60" Background="{StaticResource PhoneAccentBrush}">
                    <TextBlock Text="{Binding data}" FontSize="30" Margin="10,10,10,0"/>
                    <TextBox Height="60" Width="460" Visibility="Collapsed"/>
                </Canvas>
            </DataTemplate>
        </ListBox.ItemTemplate>
</ListBox>

The effect I wanna accomplish is : Tap textblock to hide textblock while show textbox.

CODE BEHIND:

private void TextBlock_Tap(object sender, GestureEventArgs e)
    {
        TextBlock.Visibilty = Visibility.Collapsed;
        TextBox.Visibilty = Visibility.Visible;
    }

However, obviously the selector isn’t correct. I tried to add Name for textbox and textblock, but Name seems does not work in Data Template. Is there anyone who can tell me how can i select the textblock and textbox in a Data Template please? Many Thanks!!!

  • 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-31T23:42:00+00:00Added an answer on May 31, 2026 at 11:42 pm

    Setting the Name on the template does work, but you can’t access it directly!

    Instead, try it like this:

    <ListBox x:Name="MyListBox">
        <ListBox.ItemTemplate>
            <DataTemplate>
                <Canvas Width="460" Height="60" Background="{StaticResource PhoneAccentBrush}">
                    <TextBlock x:Name="MyTextBlock" Text="{Binding data}" FontSize="30" Margin="10,10,10,0" Tap="MyTextBlock_Tap" />
                    <TextBox x:Name="MyTextBox" Height="60" Width="460" Visibility="Collapsed"/>
                </Canvas>
            </DataTemplate>
        </ListBox.ItemTemplate>
    </ListBox>
    

    And the code:

    private void MyTextBlock_Tap(object sender, GestureEventArgs e)
    {
        var elem = (FrameworkElement)sender;
    
        var myTextBlock = (TextBlock)elem.FindName("MyTextBlock");
        var myTextBox = (TextBox)elem.FindName("MyTextBox");
    
        myTextBlock.Visibility = Visibility.Collapsed;
        myTextBox.Visibility = Visibility.Visible;
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I was just wondering while programming. I have got a rootViewController which creates an
I've just started using ASP, so while programming the code behind in C# I
Been a while and I've volunteered to teach myself Windows programming at my company.
I have been programming in Python for a while now, and have created some
I have sent emails from windows using C# programming like this . It is
I'm from a Windows programming background when writing tools, but have been programming using
I am new to Windows Programming. I created a win32 console project (without preCompiled
I'm using libjpeg (C/C++ programming on Windows Mobile 6.5), in order to decode images
While programming, the longest part is a build on my ASP.NET Website project is
While programming, I often come across the following scenario (described in code). I define

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.