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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T18:32:00+00:00 2026-06-10T18:32:00+00:00

So I have a collection of objects that may be of multiple type. For

  • 0

So I have a collection of objects that may be of multiple type.
For example a base class with B, and descendents C,D,E.

All this will be in an ItemsControl, however with a custom (somehow random) logic. Therefore I create an ItemsControl in the XAML, specify the DataTemplates binding them to types and let the Silverlight implicit datatemplate engine handle the rest.

The position of the elements inside the ItemsControl presenter is somehow random, and available only at runtime as a dependency property in the element itself (part of the Base class).

My problem is that by default the ItemsControl wraps the items in a ContentPresenter Object, therefore setting the Canvas.Left and Canvas.Top in the data templates has no effect. Because this should be set on the ContentPresenter level instead. However, if I define the ContentPresenter style, the datasource of this is the ItemsControl itself, and not the items. Therefore, I cannot bind that way the positions of the items.

Any ideas, how can I bind the item position properties to the ContentPresenters Canvas.Left property?

In code terms:

<ItemsControl HorizontalAlignment="Stretch" Grid.Row="0" Grid.ColumnSpan="3"
                  x:Name="CardItems" ItemsSource="{Binding CardList}" ScrollViewer.HorizontalScrollBarVisibility="Disabled"
                  ScrollViewer.VerticalScrollBarVisibility="Disabled">
        <i:Interaction.Triggers>
            <i:EventTrigger EventName="SizeChanged">
                <ei:CallMethodAction MethodName="WndSizeChanged" TargetObject="{Binding}" />
            </i:EventTrigger>
        </i:Interaction.Triggers>
        <ItemsControl.ItemsPanel>
            <ItemsPanelTemplate>
                <Canvas/>
            </ItemsPanelTemplate>
        </ItemsControl.ItemsPanel>
    </ItemsControl>
<UserControl.Resources>
    <DataTemplate DataType="Card:AdCardViewModel">
        <Canvas d:DesignHeight="300" d:DesignWidth="150" Width="{Binding CardSize.Width}" Height="{Binding CardSize.Height}" Background="Red">
            <Canvas.Projection>
                <PlaneProjection RotationY="{Binding Path=Rotation}"/>
            </Canvas.Projection>
            <Viewbox>
                <StackPanel>
                    <StackPanel.Background>
                        <SolidColorBrush Color="{StaticResource OriginalRecommendationColor}"/>
                    </StackPanel.Background>
                    <TextBlock Text="{Binding AdCard}" Foreground="CadetBlue"/>
                </StackPanel>
            </Viewbox>
        </Canvas>
    </DataTemplate>
</UserControl.Resources>

PS. I am using the MVVM Light, so I would rather avoid using the code behind file.

LE:

This seems to work, however for some reason the Visual Studio Intellisense has not idea about it. Runtime it seems to be okay, however nothing at design time. Any ideas, how to make all this working in Blend too?

          <ItemsControl.Resources>
            <Style TargetType="ContentPresenter">
                <Setter Property="Canvas.Left"  Value="{Binding  Path=Position.Height}"/>
                <Setter Property="Canvas.Top"  Value="{Binding  Path=Position.Width}"/>
                <Setter Property="Width" Value="Auto"/>
                <Setter Property="Height" Value="Auto"/>
                <Setter Property="HorizontalAlignment" Value="Stretch"/>
                <Setter Property="VerticalAlignment" Value="Stretch"/>
            </Style>
        </ItemsControl.Resources>

The viewModelLocator:

    static ViewModelLocator()
    {
        ServiceLocator.SetLocatorProvider(() => SimpleIoc.Default);

        // Step #1 - Register the data providing services, design and runtime versions
        if (ViewModelBase.IsInDesignModeStatic)
        {
            SimpleIoc.Default.Register<ICardService, DesignCardService>();
        }
        else
        {

            SimpleIoc.Default.Register<ICardService, CardService>();

        }

        // Step#2 Register the ViewModels
        SimpleIoc.Default.Register<CardSlideShowViewModel>();
    }


    /// <summary>
    ///     Gets the Video property.
    /// </summary>
    [SuppressMessage("Microsoft.Performance",
        "CA1822:MarkMembersAsStatic",
        Justification = "This non-static member is needed for data binding purposes.")]
    public CardSlideShowViewModel CardSlideShowSlideShow
    {
        get { return ServiceLocator.Current.GetInstance<CardSlideShowViewModel>(); }
    }

Thanks,

  • 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-10T18:32:02+00:00Added an answer on June 10, 2026 at 6:32 pm

    Well, not really an answer, however the closest I come to this. It seems to me that VS 2010 does not support this, yet. However it works in VS 2012. So if you can do the upgrade.

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

Sidebar

Related Questions

I have a list/collection of objects that may or may not have the same
I have a collection FileTypes that holds objects of type FileType. That type has
I have an ItemsControl that is bound to a collection of objects. Each object
I'm looking to have a collection of objects that implement a certain interface, but
I have an observable collection of objects that I'd like to display on the
I have a Queue that contains a collection of objects, one of these objects
I have several methods that populate a SQLCommand objects parameter collection from an object
I'm stumped here. I have an observable collection that holds business objects. I have
I have an object that has a child collection: class Person { public string
I have a collection of objects that's constantly changing, and I want to display

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.