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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T11:25:13+00:00 2026-06-10T11:25:13+00:00

I have a canvas and I would love to bind some points there on

  • 0

I have a canvas and I would love to bind some points there on specified XY location. However, I can’t achieve this with ItemsControl. I found some solutions but I guess they are not for Windows Phone.

The XAML I’m using is:

<ItemsControl ItemsSource="{Binding Path=Nodes}">
    <ItemsControl.ItemsPanel>
        <ItemsPanelTemplate>
            <Canvas />
        </ItemsPanelTemplate>
    </ItemsControl.ItemsPanel>
    <ItemsControl.ItemContainerStyle>
        <Style TargetType="ContentPresenter">
            <Setter Property="Canvas.Left" Value="{Binding Path=XPos}" />
            <Setter Property="Canvas.Top" Value="{Binding Path=YPos}" />
        </Style>
    </ItemsControl.ItemContainerStyle>
</ItemsControl>

And I get: “The member “ItemContainerStyle” is not recognized or is not accessible”

How to do that kind of binding in other way? I have name of object, and X/Y values and I want to bind is as a some kind of pushpin

  • 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-10T11:25:14+00:00Added an answer on June 10, 2026 at 11:25 am

    I encountered the same issue but solved it using a TriggerAction instead. You can use the System.Windows.Interactivity if you have the Blend SDK. The dll is located in

    c:\Program Files\Microsoft SDKs\Expression\Blend\Silverlight\v4.0\Libraries\
    System.Windows.Interactivity.dll`
    

    Then, by using your previous xaml code I can set the datatemplate as such:

    <ItemsControl.ItemTemplate>
        <DataTemplate>
            <Ellipse Stroke="Red" Width="2" Height="2">
                <ia:Interaction.Triggers>
                    <ia:EventTrigger EventName="Loaded">
                        <tr:SetCanvasPropertiesAction Left="{Binding X}" Top="{Binding Y}" />
                    </ia:EventTrigger>
                </ia:Interaction.Triggers>
            </Ellipse>
        </DataTemplate>
    </ItemsControl.ItemTemplate>
    

    Note the ia:Interaction prefix, from the interactivity dll mentioned before. You load it with

    xmlns:ia="clr-namespace:System.Windows.Interactivity;assembly=System.Windows.Interactivity"
    

    in the top of your xaml file.

    The tr prefix is for including my own class, which looks like this:

    using System.Windows;
    using System.Windows.Controls;
    using System.Windows.Interactivity;
    using System.Windows.Media;
    
    namespace Presentation.Triggers {
        public class SetCanvasPropertiesAction : TriggerAction<DependencyObject> {
            public static readonly DependencyProperty LeftProperty =
                DependencyProperty.Register("Left", typeof(double), typeof(SetCanvasPropertiesAction), new PropertyMetadata(default(double)));
    
            public static readonly DependencyProperty TopProperty =
                DependencyProperty.Register("Top", typeof(double), typeof(SetCanvasPropertiesAction), new PropertyMetadata(default(double)));
    
            public double Top {
                get { return (double)GetValue(TopProperty); }
                set { SetValue(TopProperty, value); }
            }
    
            public double Left {
                get { return (double)GetValue(LeftProperty); }
                set { SetValue(LeftProperty, value); }
            }
    
            protected override void Invoke(object parameter) {
                UIElement presenter = (UIElement)VisualTreeHelper.GetParent(AssociatedObject);
                Canvas.SetLeft(presenter, Left);
                Canvas.SetTop(presenter, Top);
            }
        }
    }
    

    Two things to note with the Invoke method. The first is AssociatedObject, that gets resolved to the Ellipse since the trigger is nested under it in the xaml. The second thing is the VisualTreeHelper, which gets the parent to the ellipse. This is the ContentPresenter on which we want to set the attached properties of the canvas.

    It might look like it’s more complicated, but as with everything else in mvvm, you can reuse it in xaml and you don’t have to copy and paste code-behind code everywhere.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a canvas wich is a drawing area. This canvas can be scrolled
I have created a wpf application ,there are two canvas i would like to
I Have a canvas and would like to place silverlight elements within that canvas
I would like to have my canvas page on facebook display different content for
I have a Controls.Canvas with several shapes on it and would like to add
I have an iPad 2 canvas app (game) and would like to get it
I would like to have that the height of a canvas change automatically. When
I would like to have fuzzy looking border around my Canvas control. Basically, I
I have this canvas mousedown event: $('#canvas').mousedown(function(e) { var coords = canvas.getMousePos(e); // user
I have a little app here, and I would love to be able to

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.