Page Index Toggle Pages: [1] 2  Send TopicPrint
Hot Topic (More than 10 Replies) Import Wpf Diagram (Read 14030 times)
integragreg
YaBB Newbies
*
Offline



Posts: 40
Location: Tennessee
Joined: Jan 26th, 2009
Import Wpf Diagram
Feb 3rd, 2009 at 9:50pm
Print Post  
Would it be possible to create a diagram using the Wpf diagramming components and then load it later using the Silverlight diagramming components?

We want to create an editor application with Wpf, and a viewer in Silverlight.
  
Back to top
WWW  
IP Logged
 
Stoyo
God Member
*****
Offline


MindFusion support

Posts: 13230
Joined: Jul 20th, 2005
Re: Import Wpf Diagram
Reply #1 - Feb 4th, 2009 at 8:19am
Print Post  
Yes, it's possible. However the following features are not yet implemented in the Silverlight version, so you might get unexpected results if you are using them: ContainerNodes, ShapeNode.RotationAngle, spanning cells in TableNodes.

Stoyan
  
Back to top
 
IP Logged
 
integragreg
YaBB Newbies
*
Offline



Posts: 40
Location: Tennessee
Joined: Jan 26th, 2009
Re: Import Wpf Diagram
Reply #2 - Mar 19th, 2009 at 7:38pm
Print Post  
Can you provide a bit more guidance on how to accomplish this? We've tried it two different ways:

The first method:
1. We created a Wpf application that references the Wpf diagramming assembly
2. We create and save a diagram (it has references to the Wpf namespaces in the Class attributes)
3. We try to load the Xml into a Silverlight diagram in a Silverlight application. We get an error saying that the specified key is not in the collection.

The second method:
1. In our Wpf application, we replaced the reference to the Wpf diagramming assembly with the DiagramLite assembly. The Wpf application will not compile.

Thanks,

Greg
  
Back to top
WWW  
IP Logged
 
Stoyo
God Member
*****
Offline


MindFusion support

Posts: 13230
Joined: Jul 20th, 2005
Re: Import Wpf Diagram
Reply #3 - Mar 19th, 2009 at 8:02pm
Print Post  
Are you using controls hosted in DiagramNodeAdapters?
  
Back to top
 
IP Logged
 
integragreg
YaBB Newbies
*
Offline



Posts: 40
Location: Tennessee
Joined: Jan 26th, 2009
Re: Import Wpf Diagram
Reply #4 - Mar 19th, 2009 at 8:24pm
Print Post  
Yes.
  
Back to top
WWW  
IP Logged
 
Stoyo
God Member
*****
Offline


MindFusion support

Posts: 13230
Joined: Jul 20th, 2005
Re: Import Wpf Diagram
Reply #5 - Mar 20th, 2009 at 7:47am
Print Post  
At this time the only thing you can do is derive from DiagramNode and use RegisterItemClass with some id that will be the same in both your WPF and Silverlight application. We'll think of some way to load hosted controls for the 1.0.3 release, perhaps some event that will let you resolve the class named saved in WPF to a corresponding Silverlight class.
  
Back to top
 
IP Logged
 
integragreg
YaBB Newbies
*
Offline



Posts: 40
Location: Tennessee
Joined: Jan 26th, 2009
Re: Import Wpf Diagram
Reply #6 - Mar 23rd, 2009 at 3:12pm
Print Post  
Right now, we have Wpf custom controls with XAML templates in a Generic.xaml file. When we drag these controls onto the diagram, we automatically create a DiagramNodeAdapter.

If I understand correctly, we need to change our model to make our controls inherit from DiagramNode; but we still need the XAML markup from the template for the visual representation of the control. How do we tie the custom DiagramNode child control to the XAML template? Is there an example that we can look at to become more familiar with the concept?

Thanks
  
Back to top
WWW  
IP Logged
 
Stoyo
God Member
*****
Offline


MindFusion support

Posts: 13230
Joined: Jul 20th, 2005
Re: Import Wpf Diagram
Reply #7 - Mar 23rd, 2009 at 6:35pm
Print Post  
You could derive from DiagramNodeAdapter in WPF and ControlNode in Silverlight and use RegisterItemClass to enable custom serialization of your types. The derived classes could simply set the internal Control to an instance of what's defined in your Xaml. Then override SaveToXml and LoadFromXml to save or load the properties of the hosted controls you are interested in. We'll probably be able to implement some builtin support for loading WPF files into DiagramLite in 2-3 weeks.
  
Back to top
 
IP Logged
 
integragreg
YaBB Newbies
*
Offline



Posts: 40
Location: Tennessee
Joined: Jan 26th, 2009
Re: Import Wpf Diagram
Reply #8 - Mar 23rd, 2009 at 7:17pm
Print Post  
I think I understand the concept that you're recommending, and it seems workable for us.

To test it, we've created a custom class that inherits from DiagramNode, and we placed it into a NodeListView so that it can be dragged onto the diagram. Our problem seems to be that there is a NullReferenceException thrown when we drop the custom node from the NodeListView onto the diagram.

We are able to place an instance of our custom node on the diagram declaratively, we just cannot drag it from a toolbar and drop it onto the diagram.
  
Back to top
WWW  
IP Logged
 
integragreg
YaBB Newbies
*
Offline



Posts: 40
Location: Tennessee
Joined: Jan 26th, 2009
Re: Import Wpf Diagram
Reply #9 - Mar 23rd, 2009 at 8:56pm
Print Post  
Just to make sure that I'm being clear on our design, the way that we create the DiagramNodeAdapter instances that become part of our drawings is solely through drag/drop. We drag an item out of a custom toolbar and then reconstitute our custom control (that is built from a XAML template) on the drop. When we add the custom UIElement to the diagram, the DiagramNodeAdapter gets created; and, of course, this cannot be resolved when we open it in DiagramLite.

I'm sorry if I'm being dense here, but I'm not sure how inheriting from DiagramNode or DiagramNodeAdapter on the Wpf side will help. I see that we need to have a DiagramNode instance saved in our Wpf diagram so that it can be reloaded in DiagramLite; but we can't seem to get the drag/drop from our toolbar to work when we do it this way.

Perhaps I need to send you a more complete example offline so that you can provide some additional guidance? Or perhaps you could post a code sample that demonstrates the Wpf-to-Silverlight compatibility?

We are approaching a deadline on our project and need to get the Silverlight side of things implemented as quickly as possible.
  
Back to top
WWW  
IP Logged
 
Stoyo
God Member
*****
Offline


MindFusion support

Posts: 13230
Joined: Jul 20th, 2005
Re: Import Wpf Diagram
Reply #10 - Mar 24th, 2009 at 9:24am
Print Post  
NodeListView expects that the types of its items override the Clone method or have a copy constructor.
  
Back to top
 
IP Logged
 
Stoyo
God Member
*****
Offline


MindFusion support

Posts: 13230
Joined: Jul 20th, 2005
Re: Import Wpf Diagram
Reply #11 - Mar 24th, 2009 at 9:53am
Print Post  
Still, creating a new type for each of your custom controls doesn't look like that good idea. We'll add some events to let you resolve the type of the hosted control in Silverlight. There is another difficulty; there is no XamlReader class available in Silverlight to read automatically the properties saved by XamlWriter in WPF, so we'll have to add SaveControl and LoadControl events in the WPF version similar to the ones in DiagramLite 1.0.2.
  
Back to top
 
IP Logged
 
integragreg
YaBB Newbies
*
Offline



Posts: 40
Location: Tennessee
Joined: Jan 26th, 2009
Re: Import Wpf Diagram
Reply #12 - Mar 24th, 2009 at 12:18pm
Print Post  
That sounds good. I look forward to getting the updated binaries and trying it out.
  
Back to top
WWW  
IP Logged
 
Stoyo
God Member
*****
Offline


MindFusion support

Posts: 13230
Joined: Jul 20th, 2005
Re: Import Wpf Diagram
Reply #13 - Mar 30th, 2009 at 2:14pm
Print Post  
Hi,

Try this version:
https://mindfusion.eu/_beta/wpftosilverlight.zip

Now DiagramLite.dll should be able to load files saved by Diagramming.Wpf.dll when the diagram contains custom controls. You must handle the DeserializeControl event in Silverlight to load custom controls as shown below.

Code
Select All
private void testLoadControlWpf()
{
	d.DeserializeControl += DeserializeControl;
	d.LoadFromXml("diagram.xml");
}

void DeserializeControl(object sender, ControlNodeEventArgs e)
{
	var elt = e.XmlElement.Elements().First();
	e.Node.Control = new TextBox { Text = elt.Value };
}
 



We haven't added SerializeControl and DeserializeControl events in the WPF version; it still saves hosted controls using XamlWriter. So you must check what XML elements are generated for your controls by XamlWriter and parse them accordingly on the Silverlight side. We could add SerializeControl and DeserializeControl events in WPF too if you prefer to implement serialization yourself in both WPF and Silverlight.

I hope that helps,
Stoyan
  
Back to top
 
IP Logged
 
integragreg
YaBB Newbies
*
Offline



Posts: 40
Location: Tennessee
Joined: Jan 26th, 2009
Re: Import Wpf Diagram
Reply #14 - Mar 30th, 2009 at 2:53pm
Print Post  
Stoyan,

There appears to be a problem with the zip file. When I download it, it's only 212kB in size. Can you re-post the file?

Thanks!
  
Back to top
WWW  
IP Logged
 
Page Index Toggle Pages: [1] 2 
Send TopicPrint