2012-10-18 66 views
0

对象使用参考我是新来WPF,请不要怪我;)
我在XAML以下部分:WPF,在XAML

<ListView x:Name="listView" IsEnabled="{Binding PropertiesEnabled}" Margin="0" 
      BorderThickness="0" DragDrop1:DropTargetBehavior.IsDropTarget="true" 
      MinHeight="300" DragDrop1:DropTargetBehavior.DropType="{x:Type UIP:DataItemViewModel}" 
      ItemsSource="{Binding dataItemCollection}" 
      SelectedItem="{Binding SelectedItem, Mode=TwoWay}" 
      AllowDrop="True" KeyDown="listView_KeyDown" MouseUp="listView_MouseUp" 
      UseLayoutRounding="False" VerticalContentAlignment="Center" 
      MaxWidth="Infinity" MaxHeight="1000" Grid.Column="1" 
      HorizontalContentAlignment="Stretch"> 

在后面的视图类的代码,我能够访问listView及其大部分属性和属性,如IsEnabled,Margin,ItemsSource等。但是,当涉及到DragDrop1时,它并未列出。

为什么我需要引用DragDrop1,它是DropTargetBehavior类型的原因,因为某些事件应该以编程方式触发。

什么可能是缺少DragDrop1的原因?我如何得到它的参考?

干杯。

回答

2

该属性是一个AttachedProperty,所以它实际上不存在作为ListView对象的一部分。您需要使用AttachedProperty类名来访问该值,并将其作为参数传递给ListView以获取或设置该值。

您可以使用DragDrop1.DropTargetBehavior.GetIsDropTarget(listView)或使用DragDrop1.DropTargetBehavior.SetIsDropTarget(listView, yourValue)