1

我在包含三个按钮的网格的列表框中遇到问题。我已经在这个网格内实现了按钮的交换功能。我的问题是当我从左到右拖动按钮并且当它与另一个按钮重叠时,我的拖动按钮在拖动时显示在那个按钮的后面。但是当我从右到左拖动一个按钮时,这不会发生(正确的功能)。这是我正在使用的 Xaml 代码

<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>
4

1 回答 1

1

GestureListener_DragDelta事件中添加设置canvas.ZIndexProperty为某个值,例如。100它会正常工作。不要忘记将Zindex值设置为0拖动完成时。

于 2013-01-15T11:48:07.213 回答