Binding to DomainConext

I now have an application based on the Silverlight Business Application Template. I do have more, but they are all about presenting data in grids etc.

What I now want to do is represent this data into a diagram.

Is it possible to bind a diagram to a DomainContext and the bind the NodesSource to an EntitySet from that DomainContext?

I was trying a little example that has a table in the database called Shapes with the fileds Id, Location, DataTemplate and Text.

What do I have to do to let this work. I now get error like ‘Override InsertNode to support adding node data to NodesSource, which does not implement IList’.

Where do I have to start? Should it be possible at all, or is it just me that is still learning the pretty string, but sometimes for me mindcracking, databinding in Xaml?

Have you seen the videos at: GoSilverlight videos?

I was so close. Thanks, didn’t see the Video, but now i’. trying to get to addition of nodes. Tomorrow is a new day :)

My Diagram is now created on load. I just was forgotten to set it to the DomainContext.Data (left the .Data out).

But I now have some things that do not work.

First of all when I move my Shapes they sometimes disappear, don’t know if this is just me or something else.

What I also want is that when the Shapes move the data in the database is changed. I have the Binding Data.Location set to TwoWay, so I was thinking that the DomainContext UpdateShape would be called?

Also I need to insert the Newly added shapes on the Diagram. Do I have to override some methods?

I get an error on CopyNode1 when I drag and drop a Node from my pallet to the Diagram.

Regarding your shape Nodes disappearing: that’s odd. I suppose you could try implementing a Diagram.Model.Changed event handler so that you can see all of the events that happen – maybe you can find the reason that a Node is removed.

Also, can you characterise when they disappear and when they don’t?

What’s the error in CopyNode1? Does the message give a clue?

Ill be back on this after easter. Having weekend right now :)

I’m back again on this project.

What I now have is at startup data is read from the database. And the diagram is automatically generated. Location is also read from the database. All exact as in the VIdeo demo.

I have the GetShapes, UpdateShapes, InsertShapes and DeleteShapes in my WebService.

The diagram uses the GetShapes to get the data initially from the database when I bind in the DDS Loaded:

myDiagram.NodesSource = shapesDomainDataSource.Data;

What I now want is when the user drags a shape from my palette it is automatically inserted in the database, when he moves a shape it is updated and when he deletes a shape from the diagram it will also be deleted from the database.

I first was thinking that this will be done ‘automatically’ because the diagrams NodesSource is bound to the DDS Data.

But as far as I can see right now I do need to override some functions, Like CopyNode1, CopyNode2, DeleteNode, InsertNode and maybe even the OnChanged?

Maybe it’s just my misstake and it should all working ‘directly’?

I am trying to do the override functionality and try to find out where to do what. At this point the Shapes don’t even appear anymore on my Diagram when draggin from the palette :S

What I have in the events list is:

! Document1 AddedNode: Shape : ada99be9-0444-433d-903a-68e0e299cb08

! Document1 RemovedNode: Shape : ada99be9-0444-433d-903a-68e0e299cb08

* Document1 StartedTransaction: Drop

! Document1 AddedNode: Shape : e98ba320-7f01-40b3-bf54-55fa0c76bbac

* Document1 CommittedTransaction: ExternalCopy old: CompoundEdit: ExternalCopy 1 edits

* Document1 StartedTransaction: Layout

* Document1 CommittedTransaction: Layout

About the error on CopyNode1:

When I go ‘back’ to the mode where I dont override the functions and have them all using the GoXam functionality this is the error:

CopyNode1: override this method to copy nodes, or have node data implement ICloneable or be Serializable.


About disappearing Shapes: It’s when I move them. Not at a specific moment, but during the dragging. At a point the shape is not displayed anymore I stop dragging and these are the events that happened:

* Document1 StartedTransaction: Drag

* Document1 CommittedTransaction: MoveSelection

* Document1 StartedTransaction: Layout

* Document1 CommittedTransaction: Layout

The model doesn’t know how to copy your shape data. That’s why you are getting that error in CopyNode1.

But instead of binding to the DomainDataSource.Data, I would try using its DataView. The DomainDataSourceView supports INotifyCollectionChanged.

However, I don’t have personal experience using this. I’ll ask Jake to look into it.

OK… not sure this will help much, but to let you know I’m poking into it. If I take the OrgChart app at the end of video 2, and change the JobTitle in the NodeTemplate to be go:Part.TextEditable=“True”…

When I edit the jobtitle, I get an exception back in the BusinessApplication7.Web.Models.vEmployeeDepartment JobTitle property in the “set” method.

The ‘JobTitle’ property is read only.

So… it seems like GoXam and the binding in the video are set up to make changes correctly, if I had bothered to set up the Model appropriately.

So, I’ll work on that… once I get RIA updates back to the db, I’ll look at adding nodes…

Thanks very much. If I can provide you with extra info please let me know. I am on this project right now but doing some other things because the RIA updates to db are second priority (to my boss ;))

If I am possible to have the binding to the database to allow me add, delete and update records ‘just’ by binding this would be excellent.

I have been on different projects that have grids etc. bound to databases, but if we are able to have diagrams bound to databases that would be the ultimate :)

Please let me know If you need some more information…thanks in advance.

If I use “Title”, a field which isn’t read only, editing it does seem to work, but the change isn’t remembered in the db.

I have a vague recollection that when I set this up, there was a warning about using a “View” (vEmployeeDepartment) where it would be read only.

I’ll dig a little more…

Maybe I can setup a little example project for you so I can let you see what I mean?

Ok, I posted a little example which pretty much holds my problems. You can find it here:

When you move the shapes on the diagram you will see some moments the shape is gone from the diagram.

In the grid you’ll see the changes in the location when shapes are moved, but UpdateMyShapes is not called, so no changes in the database at all.

(Drag/Drop is not working (yet), don’t know why, but i’ll have a look at that one too for adding new data to the database).

Time for me to have some sleep, catch this up tomorrow.

I’m not seeing any issue with moving shapes within the diagram.

I haven’t looked at the database issues yet.

ok… if I add

to your Home.xaml

and this to Home.xaml.cs

private void ButtonSave_Click(object sender, System.Windows.RoutedEventArgs e) {



Voila! data saved to the MDF file. (and I do hit the breakpoint at UpdateMyShape)

And if you don’t want to implement an explicit “Save” model for your application, you can call SubmitChanges in a Model.Changed event handler each time a transaction commits or when an undo or redo has finished.

Geez, I feel so ‘stupid’ right now. Of course we need to Submit the Changes. I was so blind in other issues right now that I didn’t see this simple thing. Guys, may I thank you very very much. For a thing which was not even an issue to the GoXam.

I think I can do the add tomorrow, but first solve some other things.

I like the project involving GoXam :)

One thing I still have is disappearing shapes on this sample I sent you. try moving a bit around and you’ll see ‘flickering’ the shape. At some point it disappears. At least, here it does.

I dont even think I need the Model.Changed because I like users have to press on the Save button to save data, but also thanks for the suggestion.

Once again, great service!!! And i’ll be back.

No flickering, no disappearing in the code you sent us. That was with Windows 7, IE 9, Silverlight 4.0.60310.

I’ll let some others check and get some feedback…let you know.