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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T00:53:30+00:00 2026-06-16T00:53:30+00:00

I’m trying to create a user control that will display a collection of images.

  • 0

I’m trying to create a user control that will display a collection of images. I have the user control created with a dependency property for the collection of images. I can databind to that property and display the images fine.

However, I have hard-coded in the size of the collection and I want it to take in an arbitrary number of images and display them.

I am not sure how to dynamically create the images based on the collection of images. I’m sure there is some event that I want to respond to and create my images based on the contents of the dependency property.

public sealed partial class ImageView : UserControl
    {

        public ImageView()
        {
            this.InitializeComponent();

            scrollViewer.ZoomSnapPoints.Clear();
            scrollViewer.ZoomSnapPoints.Add(0.2f);
            scrollViewer.ZoomSnapPoints.Add(0.6f);
            scrollViewer.ZoomSnapPoints.Add(1.0f);
            scrollViewer.ZoomSnapPoints.Add(1.4f);
            scrollViewer.ZoomToFactor(0.4f);

        }


        public static readonly DependencyProperty ImagesProperty = DependencyProperty.Register("Images",
            typeof(List<VMImage>), typeof(ImageView), new PropertyMetadata(new List<VMImage>(12)));


        public List<VMImage> Images
        {
            get { return (List<VMImage>)GetValue(ImagesProperty); }
            set { SetValue(ImagesProperty, value); }
        }


    }


<ScrollViewer Height="700" Width="700"
                      x:Name="scrollViewer"
                      MinZoomFactor="0.2"
                      MaxZoomFactor="5.0"
                      ZoomSnapPointsType="Mandatory">

        <Canvas Background="Black" Width="2000" Height="2000" >

            <Image Canvas.Left="{Binding Images[0].Location.X}" 
                   Canvas.Top="{Binding Images[0].Location.Y}"
                   Source="{Binding Images[0].Source}" ></Image>
            <Image Canvas.Left="{Binding Images[1].Location.X}" 
                   Canvas.Top="{Binding Images[1].Location.Y}"
                   Source="{Binding Images[1].Source}" ></Image>
        </Canvas>

    </ScrollViewer>
  • 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-16T00:53:31+00:00Added an answer on June 16, 2026 at 12:53 am

    You should make your dependency property an ObservableCollection<VMImage>. This way you can attach a handler to its CollectionChanged event and get notified of changes. Just make sure in the property changed callback of your dependency property that you add the event handler to the new value and remove it from the old value.

    public static readonly DependencyProperty ImagesProperty = DependencyProperty.Register("Images",
        typeof(ObservableCollection<VMImage>), typeof(ImageView), new PropertyMetadata(null, OnImagesChanged));
    
    public ObservableCollection<VMImage> Images
    {
        get { return (ObservableCollection<VMImage>)GetValue(ImagesProperty); }
        set { SetValue(ImagesProperty, value); }
    }
    
    private static void OnImagesChanged(DependencyObject target, DependencyPropertyChangedEventArgs e)
    {
        // use wrapper to pass DependencyObject to handler
        NotifyCollectionChangedEventHandler handler = (s, args) => OnCollectionChanged(target, args);
        if (e.OldValue is ObservableCollection<object>)
            (e.OldValue as ObservableCollection<object>).CollectionChanged -= handler;
        if (e.NewValue is ObservableCollection<object>)
            (e.NewValue as ObservableCollection<object>).CollectionChanged += handler;
    
        var imageView = target as ImageView
        if (imageView != null)
        {
            // collection has changed completely, replace all images
        }
    }
    
    static void OnCollectionChanged(object sender, NotifyCollectionChangedEventArgs e)
    {
        var imageView = sender as ImageView;
        if (imageView != null)
        {
            if (e.OldItems != null)
            {
                // remove images
            }
            if (e.NewItems != null)
            {
                // add images
            }
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to create an if statement in PHP that prevents a single post
I am trying to understand how to use SyndicationItem to display feed which is
Basically, what I'm trying to create is a page of div tags, each has
I have a small JavaScript validation script that validates inputs based on Regex. I
I have a French site that I want to parse, but am running into
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I'm trying to convert HTML to plain text. I get many &\#8217; &\#8220; etc.
I need a function that will clean a strings' special characters. I do NOT
I am trying to loop through a bunch of documents I have to put
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function

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.