Hi,
I'm trying to use the drop manager in our MVVM WPF application, and when I try to add a DragStart or DragDrop event I keep getting the error message that the method must be part of the code behind.
This, of course, would break our MVVM pattern to put code in the code-behind of the view. Is there a workaround, and do you intend to support MVVM in the future?
Thanks.
drop manager is not part of the visual tree, so there is no normal way to bind to view model property.
only workaround i found for me is to use freezable data context proxy:
<ns:BindingProxy x:Key="BindingProxy" Data="{Binding}"></ns:BindingProxy>
and
<command:EventToCommand Command="{Binding Path=Data.DragStartCommand, Source={StaticResource BindingProxy}}"
hope this helps.
Hello,
I found this post duplicate to this one:
http://ko.infragistics.com/community/forums/p/89965/444494.aspx#444494
which is already discussed.
Any chance you can provide some more code on this? I am running into the same issue with a sample project. I tried your approach but I am still not hitting the command handler. What am I doing wrong here?
<Window x:Class="InfragisticsDragDrop.MainWindow" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:i="http://schemas.microsoft.com/expression/2010/interactivity" xmlns:ig="http://schemas.infragistics.com/xaml" xmlns:infragisticsDragDrop="clr-namespace:InfragisticsDragDrop" Title="MainWindow" Width="525" Height="350"> <Window.Resources> <ResourceDictionary> <DataTemplate x:Key="ListBoxItemTemplate" DataType="{x:Type infragisticsDragDrop:Person}"> <StackPanel Background="Transparent"> <ig:DragDropManager.DragSource> <ig:DragSource IsDraggable="True"> <i:Interaction.Triggers> <i:EventTrigger EventName="DragStart"> <i:InvokeCommandAction Command="{Binding Source={x:Reference Lb1}, Path=DragStartedCommand}" /> </i:EventTrigger> </i:Interaction.Triggers> </ig:DragSource> </ig:DragDropManager.DragSource> <TextBlock Margin="2" Text="{Binding Name}" /> <TextBlock Margin="2" Text="{Binding Age}" /> </StackPanel> </DataTemplate> </ResourceDictionary> </Window.Resources> <Grid> <Grid.ColumnDefinitions> <ColumnDefinition Width="*" /> <ColumnDefinition Width="*" /> <ColumnDefinition Width="*" /> </Grid.ColumnDefinitions> <ListBox Name="Lb1" Grid.Column="0" ItemTemplate="{StaticResource ListBoxItemTemplate}" ItemsSource="{Binding People}" /> <ListBox Name="Lb2" Grid.Column="1" Background="DarkGray" ItemsSource="{Binding DroppedPeople}"> <ig:DragDropManager.DropTarget> <ig:DropTarget IsDropTarget="True"> <i:Interaction.Triggers> <i:EventTrigger EventName="Drop"> <i:InvokeCommandAction Command="{Binding DropCommand}" /> </i:EventTrigger> </i:Interaction.Triggers> </ig:DropTarget> </ig:DragDropManager.DropTarget> </ListBox> </Grid> </Window>
Would be nice if this was supported in any way, shape, or form, seeing as MVVM is the only way people use Silverlight/WPF nowadays.