正如下面的代码,我有一个列表框。我想将 listboxitem 水平向右拖动并消失。但是当拖动它时,会弹出这个错误,
变换.X += e.HorizontalChange; [空引用异常]
我查看手表,发现 e.HorizontalChange 的值为 65.0,为什么会显示错误?以及我如何实现我的目标?
<DataTemplate x:Key="TasksListDataTemplate">
<StackPanel x:Name="stackPanel" Margin="0,0,0,10" RenderTransformOrigin="0.5,0.5">
<toolkit:GestureService.GestureListener>
<toolkit:GestureListener
DragDelta="taskitem_DragDelta"
</toolkit:GestureService.GestureListener>
<TextBlock x:Name="textBlock" TextWrapping="Wrap" Text="{Binding Title}" FontSize="{StaticResource PhoneFontSizeLarge}" HorizontalAlignment="Left" Width="432" RenderTransformOrigin="0.5,0.5">
</TextBlock>
<StackPanel x:Name="stackPanel1" Orientation="Horizontal" HorizontalAlignment="Left">
<TextBlock x:Name="textBlock1" TextWrapping="Wrap" Text="due:" d:LayoutOverrides="Width" FontSize="{StaticResource PhoneFontSizeMedium}" RenderTransformOrigin="0.5,0.5">
</TextBlock>
<TextBlock x:Name="textBlock2" TextWrapping="Wrap" Text="{Binding DueDate}" d:LayoutOverrides="Width" FontSize="{StaticResource PhoneFontSizeMedium}" RenderTransformOrigin="0.5,0.5">
</TextBlock>
</StackPanel>
</StackPanel>
</DataTemplate>
文件后面的代码是
private void taskitem_DragDelta(object sender, DragDeltaGestureEventArgs e)
{
TranslateTransform transform = (sender as StackPanel).RenderTransform as TranslateTransform;
transform.X += e.HorizontalChange;
}