Mudit Bajpai
Mudit Bajpai

Reputation: 3020

Dragging buttons in ListBox in WP7

I am facing a problem in list box which containing a Grid with three buttons. I have implemented swap feature of buttons inside this grid. My problem is when I drag button from left to right and when it overlaps another button my drag button is showing behind that one on dragging.But when i drag a button from right to left this is not happening(correct feature). Here is the Xaml code i am using

<Grid x:Name="ContentPanel" Grid.Row="1">
            <ListBox Height="Auto" Name="listbox" VerticalAlignment="Top" ItemsSource="{Binding}" Background="#00995B5B" DataContext="{Binding}" d:LayoutOverrides="Width" HorizontalAlignment="Stretch"  HorizontalContentAlignment="Stretch">
                <ListBox.ItemContainerStyle>
                    <Style TargetType="ListBoxItem">
                        <Setter Property="HorizontalContentAlignment" Value="Stretch" />
                    </Style>
                </ListBox.ItemContainerStyle>
                <ListBox.ItemTemplate>
                    <DataTemplate>
                        <Grid Height="300"  Background="{Binding RowBackgroundBrush}">
                            <Grid.ColumnDefinitions>
                                <ColumnDefinition Width="1*" ></ColumnDefinition>
                                <ColumnDefinition Width="1*" ></ColumnDefinition>
                                <ColumnDefinition Width="1*" ></ColumnDefinition>
                            </Grid.ColumnDefinitions>
                            <Button Tag="{Binding IndexListItem1.PageIndex}"  Foreground="Black" Content="1"   Grid.Column="0" HorizontalAlignment="Center"  Margin="10,9,0,0" Width="133" d:LayoutOverrides="GridBox">
                                <toolkit:GestureService.GestureListener>
                                    <toolkit:GestureListener DragDelta="GestureListener_DragDelta" DragStarted="GestureListener_DragStarted" DragCompleted="GestureListener_DragCompleted" Hold="GestureListener_Hold"/>
                                </toolkit:GestureService.GestureListener>

                            </Button>
                            <Button Tag="{Binding IndexListItem2.PageIndex}" Content="2"    Grid.Column="1" HorizontalAlignment="Center" Margin="10,9,0,0" Width="133"  d:LayoutOverrides="GridBox">
                                <toolkit:GestureService.GestureListener>
                                    <toolkit:GestureListener DragDelta="GestureListener_DragDelta" DragStarted="GestureListener_DragStarted" DragCompleted="GestureListener_DragCompleted" Hold="GestureListener_Hold"/>
                                </toolkit:GestureService.GestureListener>

                            </Button>
                            <Button Tag="{Binding IndexListItem3.PageIndex}" Grid.Column="2" Content="3"  Foreground="Red" Margin="10,9,0,0"  Width="133" HorizontalAlignment="Center"  d:LayoutOverrides="GridBox">
                                <toolkit:GestureService.GestureListener>
                                    <toolkit:GestureListener DragDelta="GestureListener_DragDelta" DragStarted="GestureListener_DragStarted" DragCompleted="GestureListener_DragCompleted" Hold="GestureListener_Hold"/>
                                </toolkit:GestureService.GestureListener>

                            </Button>
                        </Grid>
                    </DataTemplate>
                </ListBox.ItemTemplate>
            </ListBox>
        </Grid>

Upvotes: 1

Views: 246

Answers (1)

Shilpa
Shilpa

Reputation: 422

In GestureListener_DragDelta event add set canvas.ZIndexProperty to some value like 100.It will work fine.Don't forget to set the Zindex value to 0 when drag is completed.

Upvotes: 1

Related Questions