×

Discussion Board

Results 1 to 3 of 3
  1. #1
    Registered User
    Join Date
    Sep 2013
    Posts
    45

    Add move behavior to components inside ItemsControl

    I've got a Collection of items bound to an ItemsControl element.

    I need to enable the mouse dragging behavior for each element but I can't seem to make it work.
    With this I mean that the user should have the ability to tap on each item and move it to change its position on the screen

    Adding this code
    Code:
    <i:Interaction.Behaviors>
        <el:MouseDragElementBehavior/>
    </i:Interaction.Behaviors>
    will make it work but only if I put my items outside the ItemsControl.

    Here's the code of the ItemsControl component:
    Code:
    <ItemsControl ItemsSource="{Binding Items}">
        <ItemsControl.ItemTemplate>
            <DataTemplate>
                <utils:TemplateSelector Content="{Binding}"/>
            </DataTemplate>
        </ItemsControl.ItemTemplate>
    </ItemsControl>
    I also tried with the behavior inside the TemplateSelector but it's still not working.
    Here's the "updated" code

    Code:
    <ItemsControl ItemsSource="{Binding Items}">
                <ItemsControl.ItemTemplate>
                    <DataTemplate>
                        <utils:TemplateSelector Content="{Binding}">
                            <i:Interaction.Behaviors>
                                <el:MouseDragElementBehavior/>
                            </i:Interaction.Behaviors>
                        </utils:TemplateSelector>
                    </DataTemplate>
                </ItemsControl.ItemTemplate>
                <ItemsControl.ItemsPanel>
                    <ItemsPanelTemplate>
                        <Canvas HorizontalAlignment="Stretch" VerticalAlignment="Stretch"/>
                    </ItemsPanelTemplate>
                </ItemsControl.ItemsPanel>
            </ItemsControl>

  2. #2
    Nokia Developer Champion
    Join Date
    Sep 2012
    Location
    Morocco
    Posts
    292

    Re: Add move behavior to components inside ItemsControl

    Hi
    Code:
     <ItemsControl.ItemTemplate>
                    <DataTemplate>
                        <utils:TemplateSelector Content="{Binding}">
                            <i:Interaction.Behaviors>
                                <el:MouseDragElementBehavior/>
                            </i:Interaction.Behaviors>
                        </utils:TemplateSelector>
                    </DataTemplate>
                </ItemsControl.ItemTemplate>
    You've got a TemplaceSelector as an DataTemplate which normally will return a DataTemplate, I assume it will not take in consideration the MouseDragElementBehavior.
    can you please try the same code but without a TemplateSelector ? just put a simple DataTemplate like
    Code:
    <ItemsControl.ItemTemplate>
                    <DataTemplate>
                        <Grid >
    <TextBlock Text="Testing Item" />
                            <i:Interaction.Behaviors>
                                <el:MouseDragElementBehavior/>
                            </i:Interaction.Behaviors>
                        </Grid>
                    </DataTemplate>
                </ItemsControl.ItemTemplate>
    and then see if it works, If it does work then you'll have to edit the TemplateSelector and make sure it adds the behavior to the DataTemplate it returns.

    hope it helps
    Yassine,

  3. #3
    Registered User
    Join Date
    Sep 2013
    Posts
    45

    Re: Add move behavior to components inside ItemsControl

    Tried it now but it doesn't work.
    Nothing moves :\

Similar Threads

  1. Moving controls in a ItemsControl
    By StepTNT in forum Windows Phone General
    Replies: 0
    Last Post: 2013-09-20, 15:57
  2. Replies: 0
    Last Post: 2010-08-31, 04:05
  3. How to move between GUI components?
    By birch01 in forum Symbian User Interface
    Replies: 1
    Last Post: 2010-07-05, 09:12
  4. Red Key Behavior
    By stavrospapa in forum Symbian
    Replies: 2
    Last Post: 2009-04-14, 11:17
  5. Emulator odd behavior
    By karlbaldwin in forum Symbian Tools & SDKs
    Replies: 1
    Last Post: 2006-11-02, 04:55

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •