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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T08:35:46+00:00 2026-05-14T08:35:46+00:00

For my first Silverlight app, I’ve written a program that sends user-supplied search strings

  • 0

For my first Silverlight app, I’ve written a program that sends user-supplied search strings to the Flickr REST API and displays the results in a DataGrid. Said grid is defined like so:

<data:DataGrid x:Name="PhotoGrid" AutoGenerateColumns="False">
    <data:DataGrid.Columns>
        <data:DataGridTextColumn Header="Photo Title" Binding="{Binding Title}" CanUserSort="True" CanUserReorder="True" CanUserResize="True" IsReadOnly="True" />
        <data:DataGridTemplateColumn Header="Photo" SortMemberPath="ImageUrl">
            <data:DataGridTemplateColumn.CellTemplate>
                <DataTemplate>
                    <StackPanel Orientation="Horizontal" VerticalAlignment="Center">
                        <TextBlock Text="Click here to show image" MouseLeftButtonUp="ShowPhoto"/>
                        <Image Visibility="Collapsed" MouseLeftButtonUp="HidePhoto"/>
                    </StackPanel>
                </DataTemplate>
            </data:DataGridTemplateColumn.CellTemplate>
        </data:DataGridTemplateColumn>
    </data:DataGrid.Columns>
</data:DataGrid>

It’s a simple two-column table. The first column contains the title of the photo, while the second contains the text ‘Click here to show image’. Clicks there call ShowPhoto(), which updates the Image element’s Source property with a BitmapImage derived from the URI of the Flickr photo, and sets the image’s visibility to Visible. Clicking on the image thus revealed hides it again. All of this was easy to implement and works perfectly.

But whenever I click on one of the column headers to sort by that column, the cells that I’ve updated in this way do not change. The rest of the DataGrid is resorted and updated appropriately, but those cells remain behind, detached from the rest of their row. This is very strange, and not at all what I want.

What am I doing wrong? Should I be freshening the DataGrid somehow in response to the sort event, and if so how? Or if I’m not supposed to be messing with the contents of the grid directly, what’s the right way to get the behavior I want?

  • 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-14T08:35:47+00:00Added an answer on May 14, 2026 at 8:35 am

    I think you should Bind the Image Source to an element in a collection and update that element in the code behind instead of modifying the element directly. Make sure your property generates a property changed event and your main object implements INotifyPropertyChanged

        public string Url
        {
            get { return url; }
            set
            {
                url = value;
                NotifyPropertyChanged("Url");
            }
        }
    
        public event PropertyChangedEventHandler PropertyChanged;
    
        private void NotifyPropertyChanged(String info)
            {
                if (PropertyChanged != null)
                {
                    PropertyChanged(this, new PropertyChangedEventArgs(info));
                }
            }
    

    ********************* Adding the code to clarify ***********************
    You should probably reset the row height when you hide an image.
    I don’t see any issues with smearing and images in the background. Here is my code

    <DataTemplate>
        <StackPanel Orientation="Horizontal" VerticalAlignment="Center">
            <Button Click="ShowHidePhoto" Content="show/hide" Tag="{Binding}"/>
            <Image Visibility="{Binding Visible}" Source="{Binding Url}" MouseLeftButtonUp="OnImageClick"/>
        </StackPanel>
    </DataTemplate>
    

    code behind

    private void ShowHidePhoto(object sender, RoutedEventArgs e)
    {
        DataHolder dh = (DataHolder)((Button)sender).Tag;
        dh.Visible = dh.Visible == Visibility.Collapsed ? Visibility.Visible : Visibility.Collapsed;
        // reset height here....
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 385k
  • Answers 385k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer This was how I did it: response.header["Accept-Ranges"] = "bytes" send_file… May 14, 2026 at 11:34 pm
  • Editorial Team
    Editorial Team added an answer http://weblogs.asp.net/scottgu/archive/2008/11/24/new-asp-net-charting-control-lt-asp-chart-runat-quot-server-quot-gt.aspx May 14, 2026 at 11:34 pm
  • Editorial Team
    Editorial Team added an answer ABNewPersonViewController is what you're looking for. May 14, 2026 at 11:34 pm

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

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.