我想在WPF應用程序中承載工作流設計器。 WorkflowView控件位於WindowsFormsHost控件下。我設法將工作流加載到成功鏈接到PropertyGrid的設計器上,而該PropertyGrid也託管在另一個WindowsFormsHost中。不能將活動從WPF列表框拖入工作流視圖
WorkflowView workflowView = rootDesigner.GetView(ViewTechnology.Default) as WorkflowView;
window.WorkflowViewHost.Child = workflowView;
大部分重新託管代碼的相同的http://msdn.microsoft.com/en-us/library/aa480213.aspx。
我創建了一個自定義工具箱,它使用綁定到ToolboxItems列表的ListBox WPF控件。
<ListBox Grid.Row="1" Margin="0 0 0 4" BorderThickness="1" BorderBrush="DarkGray" ItemsSource="{Binding Path=ToolboxItems}" PreviewMouseLeftButtonDown="ListBox_PreviewMouseLeftButtonDown" AllowDrop="True">
<ListBox.Resources>
<vw:BitmapSourceTypeConverter x:Key="BitmapSourceConverter" />
</ListBox.Resources>
<ListBox.ItemTemplate>
<DataTemplate DataType="{x:Type dd:ToolboxItem}">
<StackPanel Orientation="Horizontal" Margin="3">
<Image Source="{Binding Path=Bitmap, Converter={StaticResource BitmapSourceConverter}}" Height="16" Width="16" Margin="0 0 3 0" />
<TextBlock Text="{Binding Path=DisplayName}" FontSize="14" Height="16" VerticalAlignment="Center" />
<StackPanel.ToolTip>
<TextBlock Text="{Binding Path=Description}" />
</StackPanel.ToolTip>
</StackPanel>
</DataTemplate>
</ListBox.ItemTemplate>
</ListBox>
在ListBox_PreviewMouseLeftButtonDown處理程序:
private void ListBox_PreviewMouseLeftButtonDown(object sender, MouseButtonEventArgs e)
{
ListBox parent = (ListBox)sender;
UIElement dataContainer;
//get the ToolboxItem for the selected item
object data = GetObjectDataFromPoint(parent, e.GetPosition(parent), out dataContainer);
//if the data is not null then start the drag drop operation
if (data != null)
{
DataObject dataObject = new DataObject();
dataObject.SetData(typeof(ToolboxItem), data);
DragDrop.DoDragDrop(parent, dataObject, DragDropEffects.Move | DragDropEffects.Copy);
}
}
使用這個配置,我無法從我的自定義工具箱拖動任何項目到設計。設計器上的光標始終顯示爲「否」。
我一直試圖在網上找到關於此事半天的事情,我真的希望有人能幫助我。
任何反饋是非常感謝。謝謝!
Carlos
是的,我已經在WindowsFormsHost和WorkflowView控制檢查的AllowDrop都和他們都設置爲true。我還處理了DragEvent,而e.Data參數字段包含了我在調用DragDrop.DoDragDrop之前所做System.Windows.DataObject的System.Windows.Forms.DataObject等價物。我能夠從e.Data中獲得ToolboxItem。 – ca7l0s 2009-11-19 09:39:36