Question

For a project we are trying to implement a simple card stack using WPF and the surface SDK. Everything is going well so far. We use a LibraryStack for the card deck and a ScatterView for the cards that have been taken from the stack. The Cards as well as the card stack are implemeneted as separate user controls derived from ScatterViewItem and LibraryStack. The Drag and Drop functionality also works.

However, the cards that are displayed on the LibraryStack are not aligned and each one has a different orientation. Is there any way this can be fixed so that the cards all face in the same direction?

Here is the XAML code for the CardDeck:

<s:LibraryStack x:Class="ActionCardAlt.Deck"
            ... (Standard xmlns declarations)
         xmlns:local="clr-namespace:ActionCardAlt"
             mc:Ignorable="d" 
             ItemTemplate="{DynamicResource CardBackground}"
              >
    <s:LibraryStack.Resources>
       <DataTemplate x:Key="CardBackground">
          <Image Source="Images/CardBacksideAlpha.png"> 
       </DataTemplate>
    </s:LibraryStack.Resources>
    <s:LibraryStack.Template>
       <ControlTemplate TargetType="{x:Type s:LibraryStack}">
          <Grid>
             <ItemsPresenter />
          </Grid>
       </ControlTemplate>
    </s:LibraryStack.Template>
</s:LibraryStack>

The CardDeck is placed by this command:

I would assume, that there is an option in the DataTemplate or the Image inside the DataTemplate to control the orientation. However, setting the matrices in Image.RenderTransforms to no rotation or the identity matrix didn't help.

Iterating through the Items property only changed the way, the items are displayed when they are dragged out to the ScatterView.

So, is there any possible way to do this either in the XAML or the code behind or any other trick?

Thank You very much in advance.

Was it helpful?

Solution

I dont think that is possible, even by trying to manipulate the transforms Microsoft is using for the LibraryStackItems. i have tried it myself and nothing was working. (Manipulating the RotateTransform, adding another RotateTransform to negate the initial RotateTransform etc.). Event if you get the initial Layout with zero Rotation, some weired logic will mess up your changes. And thats just the RotateTransform. There is a TranslateTransform too.. (and a ScaleTransform and a ScewTransform)

I think we just have to accept, thats how the control works and that its not appropriate to manipulate the rotation.

So here is my advise, based on many projects with the SurfaceSDK on Microsoft PixelSense itself and the Surface-Touch-Pack:

Use a single ScatterView for both of your requirements: The stack and the cards removed by the user. A stack is easily coded with a ScatterView and the Rotation can be set with the Orientation-property. And as a nice side-effect, it is really easy to handle the transitations between the stack and the opened cards.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top