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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T04:23:26+00:00 2026-06-10T04:23:26+00:00

I want to show multiple image on a canvas. I need to position them

  • 0

I want to show multiple image on a canvas. I need to position them differently in the canvas. I made a class for my images :

class MapItem:Image
{
  public int DistanceToTop { get; set; }
  public int DistanceToLeft { get; set; }
}

My XAML looks like this :

<UserControl.DataContext>
    <Map:MapViewModel/>
</UserControl.DataContext>

<ItemsControl ItemsSource="{Binding All}">
    <ItemsControl.ItemsPanel>
        <ItemsPanelTemplate>
            <Canvas />
        </ItemsPanelTemplate>
    </ItemsControl.ItemsPanel>
    <ItemsControl.ItemContainerStyle>
        <Style TargetType="Image">
            <Setter Property="Canvas.Left" Value="{Binding DistanceToLeft}" />
            <Setter Property="Canvas.Top" Value="{Binding DistanceToTop}" />
        </Style>
    </ItemsControl.ItemContainerStyle>
</ItemsControl>

My ViewModel used as DataContext :

class MapViewModel : ViewModelBase
{
  public ObservableCollection<MapItem> All   { get; set; }

  public MapViewModel()
  {
    All = new ObservableCollection<MapItem>();
    var wSource = new BitmapImage(new Uri(@"ImagePath"));
    var wImage = new MapItem { Source = wSource, DistanceToLeft = 20, DistanceToTop = 20 };
    test = wImage;
    All.Add(wImage);
  }
}

Why in the XAML my binding to DistanceToLeft and DistanceToTop are not working ?!?
Isn’t it suppose to automatically look in the object use in my ObservableCollection ?

EDIT : I still have my problem. But now I know it’s related with the Binding. I’m trying to implement all this using the MVVM pattern using the GalaSoft framework. So to start I set my DataContext to my MapViewModel. Why can’t I acces the properties of the MapItem from my ObservableCollection ?

EDIT : Finally with the help of Clemens and Rachel I ended up with this.

My MapItem Class:

class MapItem:Image
{
  public LatLon CoordMiddleOfImage { get; set; }
  public LatLon CoordTopLeftOfImage { get; set; }

  public int DistanceToTop
  {
    get { return (int) Canvas.GetTop(this); }
    set { Canvas.SetTop(this, value); }
  }

  public int DistanceToLeft
  {
    get { return (int)Canvas.GetLeft(this); }
    set { Canvas.SetLeft(this, value); }
  }

  public int ZOrder
  {
    get { return Panel.GetZIndex(this); }
    set { Panel.SetZIndex(this, value); }
  }
}

And my XAML like this :

<ItemsControl ItemsSource="{Binding All}">
    <ItemsControl.ItemsPanel>
        <ItemsPanelTemplate>
            <Canvas ClipToBounds="True"  SnapsToDevicePixels="True"/>
        </ItemsPanelTemplate>
    </ItemsControl.ItemsPanel>
</ItemsControl>

It works like a charm for now 🙂

  • 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-10T04:23:28+00:00Added an answer on June 10, 2026 at 4:23 am

    I don’t quite understand why after all you invented the DistanceToLeft and DistanceToTop properties and then struggle with binding. If you want to use Image controls as items, why not directly apply the attached properties Canvas.Left and Canvas.Top:

    All = new ObservableCollection<Image>(); // no need for derived MapItem
    var wSource = new BitmapImage(new Uri(@"ImagePath")); 
    var wImage = new Image { Source = wSource }; 
    Canvas.SetLeft(wImage, 20);
    Canvas.SetTop(wImage, 20);
    All.Add(wImage); 
    

    Hence, no need for a Style:

    <ItemsControl ItemsSource="{Binding All}">    
        <ItemsControl.ItemsPanel>    
            <ItemsPanelTemplate>    
                <Canvas />    
            </ItemsPanelTemplate>    
        </ItemsControl.ItemsPanel>    
    </ItemsControl> 
    

    However, you should consider to create a real ViewModel class that is not a control, something like this:

    public class ImageItem
    {
        public string Source { get; set; }
        public double Left { get; set; }
        public double Top { get; set; }
    }
    

    Use it similar to your MapItem class

    All = new ObservableCollection<ImageItem>();
    ImageItem image = new ImageItem { Source = @"ImagePath", Left = 20, Top = 20 };
    All.Add(image);
    

    You would now define an ItemContainerStyle like this:

    <ItemsControl.ItemContainerStyle>
        <!-- ContentPresenter is the default item container in ItemsControl -->
        <Style TargetType="ContentPresenter">
            <Setter Property="Canvas.Left" Value="{Binding Left}"/>
            <Setter Property="Canvas.Top" Value="{Binding Top}"/>
            <Setter Property="ContentTemplate">                        
                <Setter.Value>
                    <DataTemplate>
                        <Image Source="{Binding Source}"/>
                    </DataTemplate>
                </Setter.Value>
            </Setter>
        </Style>
    </ItemsControl.ItemContainerStyle>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have an image, and I want to show the same image multiple times
I want to show multiple image in each cell of TableView which is coming
I want to know how to show multiple image in a table like as
I want to show multiple detail section in my jasper report. How to add
I have a grid that has multiple rows. I want to hide/show one of
I'm trying to use the Fancy Zomm jQuery plugin to show multiple images in
could any one suggest me the way to show multiple images in tab of
I want have this ability to select multiple items with checkboxes and delete them
I want to access google maps in iphone to show the multiple locations of
Possible Duplicate: multiple upload images on c#/jquery hey guys! Yesterday i made here a

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.