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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T15:36:12+00:00 2026-06-17T15:36:12+00:00

I am adding items to a grid view on the click of a button

  • 0

I am adding items to a grid view on the click of a button and i want different items to have different images. There are 6 items and i dont want to create 6 different templates. Is there any way that i can do this with a single template? below is a code snippet of my data template :

<StackPanel>


                <!-- Shadow -->
                <Image Source="{Binding Time, Converter={StaticResource ThemeImageConverterClockShadow}}" Stretch="None" HorizontalAlignment="Left" VerticalAlignment="Top" Canvas.Left="10"
                    Canvas.Top="25"/>



                <!-- Face -->
                <Image Source="{Binding Time, Converter={StaticResource FaceBackground}}" Stretch="None" HorizontalAlignment="Left" VerticalAlignment="Top" Canvas.Left="10"
                    Canvas.Top="10" />
<StackPanel/>

I want to change only the shadow image for each item. I tried binding a property and returning a different image based upon the no. of grid view items present. But the image changes for all the grid view items whenever a new item is added to the gridview

Update:
Gridview if it helps

<GridView              


         x:Name="ThemeGridView"                    
                ItemsSource="{Binding Clocks}" 
                ItemTemplate="{StaticResource WorldClockTemplate}"
                SelectionChanged="Clock_SelectionChanged"              
                ScrollViewer.HorizontalScrollBarVisibility="Disabled"
                HorizontalAlignment="Center"
                VerticalAlignment="Center" ItemContainerStyle="{StaticResource GridViewItemStyle1}">
            <GridView.ItemsPanel>
                <ItemsPanelTemplate>
                    <WrapGrid />
                </ItemsPanelTemplate>
            </GridView.ItemsPanel>

        </GridView>
  • 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-06-17T15:36:13+00:00Added an answer on June 17, 2026 at 3:36 pm

    I think I know what’s going on with your code. I’m guessing that you are using the GridView item count in your converter ThemeImageConverterClockShadow to select the appropriate image. Whenever a new item is added to the GridView all the bindings will most likely be reevaluated, which explains why you get the same image for all the rows. What you should be doing instead is to have a property on your data item which indicates which shadow image to use, and the value should be set when you add a new item to the ItemsSource.

    One alternative would be:

    <StackPanel>
        <!-- Shadow -->
        <Image Source="{Binding ShadowImage}" Stretch="None" HorizontalAlignment="Left" VerticalAlignment="Top" Canvas.Left="10"
                    Canvas.Top="25"/>
    
        <!-- Face -->
        <Image Source="{Binding Time, Converter={StaticResource FaceBackground}}" Stretch="None" HorizontalAlignment="Left" VerticalAlignment="Top" Canvas.Left="10"
                    Canvas.Top="10" />
    <StackPanel/>
    

    where you have a property ImageSource ShadowImage on your data item in the ItemsSource:

    public class MyDataItem 
    {
        ....
        public ... Time { get { ... } set { ... } }
        public ImageSource ShadowImage { get { ... } set { ... } }
    }
    

    You then set the image when you create the data item in the code which adds a row to the GridView. Alternatively, you could add some ShadowType property instead, and then still use the converter but bind to the entire data item and then use both the Time and ShadowType to select the image:

    <StackPanel>
        <!-- Shadow -->
        <Image Source="{Binding Converter={StaticResource ThemeImageConverterClockShadow}}" Stretch="None" HorizontalAlignment="Left" VerticalAlignment="Top" Canvas.Left="10"
                    Canvas.Top="25"/>
    
        <!-- Face -->
        <Image Source="{Binding Time, Converter={StaticResource FaceBackground}}" Stretch="None" HorizontalAlignment="Left" VerticalAlignment="Top" Canvas.Left="10"
                    Canvas.Top="10" />
    <StackPanel/>
    

    with a Converter along the lines of:

    public class ThemeImageConverterClockShadow : IValueConverter
    {
        public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
        {
            var dataItem = value as MyDataItem;
            if (dataItem != null)
            {
               // Use dataItem.Time and dataItem.ShadowType to select an image
            }
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a grid view that I want to use with JavaScript to calculate
so I have a problem with dynamically adding items to menuStrip. I mean I
I'd like to move items from one list view to another. adding them to
When adding items to a gridview, I want the user to be able to
I would like to create a grid view in my iPhone app similar to
I have an item template in a GridView and I want to create a
I have a View which has a list of items bound to my ViewModel
I want to create loading progress bar when my activity is starting. I have
Im adding items to TreeView control via ItemsSource property and ItemTemplate property to set
In my Phonegap android application dynamically adding list items to jqm listview where on

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.