views:

498

answers:

3

Interface functionality isn't important (right now) with the children, but it would be handy if there were some way to say that the child can be both "here" and "there" and that it should be treated as a single object.

I am implementing a repeating, scrolling viewer that treats its canvas as a repeating plane, and I would like to be able to have it intelligently repeat child elements when the size occupied by all the displayed objects is less than the size of the panel. That is, at least one element would be shown twice.

AFAIK, this isn't possible using a naive panel implementation? Is there some wizardry I can use to arrange an element on the screen twice?

+1  A: 

I would just use two lists with the same information. I may not be the best for perfomance, (I have no data for or against), but if you're using a VirtualizingScrollViewer it will only render whats visible.

<Window>
  <Window.Resources>
    <local:MyDataSource x:Key="myDataSource" />

    <ItemsPanelTemplate x:Key="stackTemplate">
        <StackPanel IsItemsHost="True" />
    </ItemsPanelTemplate>
  </Window.Resources>
  <Border>

    <ScrollViewer>
      <StackPanel VirtualizingStackPanel.IsVirtualizing="True" DataContext="{StaticResource cusomtersDataSource}">
        <ItemsControl ItemsSource="{Binding Customers}" ItemsPanel="{StaticResource stackTemplate}" />
        <ItemsControl ItemsSource="{Binding Customers}" ItemsPanel="{StaticResource stackTemplate}" />
      </StackPanel>
    </ScrollViewer>
  </Border>
</Window>
bendewey
Kind of a work around, the only way I can accomplish this is through adding the elements (directly or indirectly) multiple times? I mean, there's no method to render twice?
Yea, like I said I'm not sure how this would affect performance. but thats why its in a VirtualizingStackPanel
bendewey
+1  A: 

Have you tried using a visualbrush with tiling, or if you want to be able to position the "mirrored" element independently use a Rectangle with the VisualBrush as Fill.

I´m not entirely sure that we are on the same track here...

Simon Söderman
The visualbrush is non-interactive though. The idea is that I'd like to essentially be able to use the ArrangeOverride to "arrange" an element multiple times. You know, here, there, etc.
Yeah, that´s not possible afaik. an itemscontrol with datatemplates that position themself on the itemscontrols panel depending on the data is the closest you´ll get (I would guess) :)
Simon Söderman
+1  A: 

I don't think it is possible to render an element in two locations (since each element keeps track of its own size/location from the Measure/Arrange pass). Furthermore, you can't add an element as a child to two parents, you'll get an exception.

The VisualBrush approach is probably going to get you closest, but as you commented on that answer, it is not interactive. Are you interested in displaying UIElements, or are you bound to some data? If you are displaying a data object, you can always create a new ContentPresenter, and set it's content to the data object. If you are displaying a UIElement, not sure if there is a way to accomplish your goal.

Abe Heidebrecht