作爲下面的代碼,我有一個listboxitem。 我想將listboxitem水平拖到右側並消失。 但拖動它時,彈出此錯誤,如何拖動WP7中的listboxitem?
transform.X + = e.HorizontalChange; [NullReferenceException]
我檢查Watch,發現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;
}
它就像一個魅力!非常感謝解決方案和解釋。 –