Page Index Toggle Pages: 1 Send TopicPrint
Normal Topic Setting Image on ShapeNode in xaml (Read 1331 times)
cthompso
YaBB Newbies
*
Offline



Posts: 6
Joined: May 27th, 2009
Setting Image on ShapeNode in xaml
Jun 2nd, 2009 at 10:25pm
Print Post  
1) What is the best way to set the Image on a ShapeNode in a NodeListView in xaml?   
2) I created a class that inherits from ShapeNode and added it to the NodeListView.  The class is barebones with no implementation.  The node shows up in the NodeListView just fine.  However, when I drag it on the diagram, I get an error (stack trace below).  Why would that throw an error and the other ShapeNodes in the NodeListView do not?
3) This question isn't specific to WPFDiagram but how do I protect my WPF app from crashing from an error thrown in
MindFusion.Diagramming.Wpf.Diagram.OnDrop(DragEventArgs e)?

<mindfusion:NodeListView Name="nodeListView">
       <mindfusion:ShapeNode Shape="Rectangle" Bounds="2,2,25,25" mindfusion:NodeListView.Label="SQL"/>
       <mindfusion:ShapeNode Shape="Rectangle" Bounds="2,2,25,25" mindfusion:NodeListView.Label="CMD"/>
       <abc:CustomNode></abc:CustomNode>
    </mindfusion:NodeListView>




"Object reference not set to an instance of an object."


   at MindFusion.Diagramming.Wpf.Diagram.OnDrop(DragEventArgs e)
   at System.Windows.UIElement.OnDropThunk(Object sender, DragEventArgs e)
   at System.Windows.DragEventArgs.InvokeEventHandler(Delegate genericHandler, Object genericTarget)
   at System.Windows.RoutedEventArgs.InvokeHandler(Delegate handler, Object target)
   at System.Windows.RoutedEventHandlerInfo.InvokeHandler(Object target, RoutedEventArgs routedEventArgs)
   at System.Windows.EventRoute.InvokeHandlersImpl(Object source, RoutedEventArgs args, Boolean reRaised)
   at System.Windows.UIElement.RaiseEventImpl(DependencyObject sender, RoutedEventArgs args)
   at System.Windows.UIElement.RaiseEvent(RoutedEventArgs e)
   at System.Windows.OleDropTarget.RaiseDragEvent(RoutedEvent dragEvent, Int32 dragDropKeyStates, Int32& effects, DependencyObject target, Point targetPoint)
   at System.Windows.OleDropTarget.MS.Win32.UnsafeNativeMethods.IOleDropTarget.OleDrop
(Object data, Int32 dragDropKeyStates, Int64 point, Int32& effects)
   at MS.Win32.UnsafeNativeMethods.DoDragDrop(IDataObject dataObject, IOleDropSource dropSource, Int32 allowedEffects, Int32[] finalEffect)
   at System.Windows.OleServicesContext.OleDoDragDrop(IDataObject dataObject, IOleDropSource dropSource, Int32 allowedEffects, Int32[] finalEffect)
   at System.Windows.DragDrop.OleDoDragDrop(DependencyObject dragSource, DataObject dataObject, DragDropEffects allowedEffects)
   at System.Windows.DragDrop.DoDragDrop(DependencyObject dragSource, Object data, DragDropEffects allowedEffects)
   at MindFusion.Diagramming.Wpf.NodeListView.OnPreviewMouseMove(MouseEventArgs e)
...
  
Back to top
 
IP Logged
 
Stoyo
God Member
*****
Offline


MindFusion support

Posts: 13230
Joined: Jul 20th, 2005
Re: Setting Image on ShapeNode in xaml
Reply #1 - Jun 3rd, 2009 at 5:59am
Print Post  
1) That's possible with this version:
https://mindfusion.eu/_beta/wpfdiag_listview_imgs.zip

After the opening Window tag, define a resource dictionary with some images

Code
Select All
<Window.Resources>
	<ResourceDictionary>
		<BitmapImage x:Key="img1" UriSource="1.jpg"  />
	</ResourceDictionary>
</Window.Resources>
 



and use the {StaticResource} syntax to access them from Xaml

Code
Select All
<Wpf:NodeListView >
	<Wpf:ShapeNode Text="node" Bounds="0,0,30,30" Image= "{StaticResource img1}"  />
</Wpf:NodeListView>
 



2) From what I can see in the drag-and-drop code, I suppose it expects that the node either defines a copy constructor or overrides the DiagramItem.Clone method.

3) You could derive from the Diagram class, override OnDrop and add try/catch around the base.OnDrop call.

I hope that helps,
Stoyan
  
Back to top
 
IP Logged
 
Page Index Toggle Pages: 1
Send TopicPrint