MVVMLight を使用せずに、できれば Icommands と対話トリガーを使用して、mvvm を使用して写真のリストボックスへのドラッグ アンド ドロップを実装する必要がありますが、コマンドを使用する場合、コマンド パラメーターに何を渡せばよいかわかりません。何か案は?ありがとう。
私が試したいくつかのアイデアを次に示します。
Public Property ImageList As New ObservableCollection(Of ListBoxItem)
Public Property AddImageCommand As ICommand = New Adjuster.DelegateCommand(AddressOf addImage)
Public Property DropCommand As ICommand = New Adjuster.DelegateCommand(AddressOf dropImage)
'Private Shared ReadOnly PreviewDropCommandProperty As DependencyProperty =
' DependencyProperty.RegisterAttached("PreviewDropCommand", GetType(ICommand), GetType(TestDocumentViewModel), New PropertyMetadata(PreviewDropCommandPropertyChangedCallBack))
Private Sub addImage()
Dim dlg As New Microsoft.Win32.OpenFileDialog()
dlg.ShowDialog()
End Sub
Private Sub dragImage(parm As Object)
Throw New NotImplementedException
End Sub
Private Sub dropImage(e As Object)
Dim droppedFilePaths As String() = TryCast(e.Data.GetData(DataFormats.FileDrop, True), String())
For Each droppedFilePath As String In droppedFilePaths
Dim fileItem As New ListBoxItem()
fileItem.Content = System.IO.Path.GetFileNameWithoutExtension(droppedFilePath)
fileItem.ToolTip = droppedFilePath
ImageList.Add(fileItem)
RaisePropertyChanged("ImageList")
'DropListBox.Items.Add(fileItem)
Next
End Sub
'Private Shared Function GetPreviewDropCommand(inUIElement As UIElement) As ICommand
' Return DirectCast(inUIElement.GetValue(PreviewDropCommandProperty), ICommand)
'End Function
'Private Shared Sub PreviewDropCommandPropertyChangedCallBack(inDependencyObject As DependencyObject, inEventArgs As DependencyPropertyChangedEventArgs)
' Dim uiElement As UIElement = TryCast(inDependencyObject, UIElement)
' If uiElement Is Nothing Then
' Return
' End If
' uiElement.Drop += Function(sender, args) Do
' GetPreviewDropCommand(uiElement).Execute(args.Data)
' args.Handled = True
'End Sub
'End Sub
クラス終了
wpf
<ListBox ItemsSource="{Binding ImageList}" VerticalAlignment="Stretch" HorizontalAlignment="Stretch" Width="Auto" Height="Auto" AllowDrop="True" Name="ImageListBox" >
<i:Interaction.Triggers>
<i:EventTrigger EventName="Drop">
<i:InvokeCommandAction Command="{Binding Path=DropCommand}" CommandParameter="{Binding }" />
<!--<cmd:EventToCommand Command="{Binding Path=DropCommand}" PassEventArgsToCommand="True" />-->
</i:EventTrigger>
</i:Interaction.Triggers>
</ListBox>