我在列表框中遇到问题,其中包含带有三个按钮的网格。 我在这个网格中实现了按钮的交换功能。 我的问题是当我从左向右拖动按钮并且当它与另一个按钮重叠时 拖动时我的拖动按钮显示在后面。但是当我从右向左拖动一个按钮时,这不会发生(正确的功能)。 这是我正在使用的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>
答案 0 :(得分:1)
在GestureListener_DragDelta
事件中将canvas.ZIndexProperty
添加到某个值100
。它会正常工作。不要忘记将Zindex
值设置为{{1}当拖动完成时。