New Posts New Posts RSS Feed: Bindings don't seem to update..?
  FAQ FAQ  Forum Search   Calendar   Register Register  Login Login

Bindings don't seem to update..?

 Post Reply Post Reply
Author
Siyfion View Drop Down
Groupie
Groupie
Avatar

Joined: 22-Mar-2012
Location: Bristol, UK
Posts: 47
Post Options Post Options   Quote Siyfion Quote  Post ReplyReply Direct Link To This Post Topic: Bindings don't seem to update..?
    Posted: 18-Apr-2012 at 9:24am
Further to my original discussion point here:  http://www.ideablade.com/forum/forum_posts.asp?TID=3377&title=binding-to-visual-objects-in-the-model

I have been attempting to try out a few of the suggestions contained within that thread and the links from it. However, I am struggling when it comes to getting the bindings to work correctly. I have a right click menu on the TextBlockEntity View that triggers a MakeBold() function in the ViewModel. This successfully updates the entity's value, but the View is never notified of the change...

The same project is available here: uploads/1418/VisualEntityMappingTest.rar

If someone could take a look and point me in the right direction, it'd be much appreciated!
Back to Top
JohnBloom View Drop Down
Groupie
Groupie
Avatar

Joined: 30-Nov-2010
Location: Topeka, KS
Posts: 95
Post Options Post Options   Quote JohnBloom Quote  Post ReplyReply Direct Link To This Post Posted: 18-Apr-2012 at 2:21pm
I cant get the link to your project to work.
 
Even though I cant see your project I would guess that you are missing a NotifyOfPropertyChanged() call. 9 times out of 10 this is what it is for me. Also if the view is setting a value back to the vm you need to have "Mode = TwoWay" in your binding. I cant remember what it is by default but I think it is just one way binding.
 
From the previous discussion it might also be that your valueconverter is not being set up right. You should be able to put a breakpoint in your converter and see what it is doing to make sure that it is updating the binding correctly.
-John Bloom
Back to Top
JohnBloom View Drop Down
Groupie
Groupie
Avatar

Joined: 30-Nov-2010
Location: Topeka, KS
Posts: 95
Post Options Post Options   Quote JohnBloom Quote  Post ReplyReply Direct Link To This Post Posted: 18-Apr-2012 at 2:33pm
I got the link to work now. I didnt have a way to view rar files so it was saving it as an xml.
-John Bloom
Back to Top
DenisK View Drop Down
IdeaBlade
IdeaBlade


Joined: 25-Aug-2010
Posts: 715
Post Options Post Options   Quote DenisK Quote  Post ReplyReply Direct Link To This Post Posted: 18-Apr-2012 at 5:56pm
Hi Siyfion,

John Bloom is correct. My knowledge of binding is limited but the change notification works if I modify a few things as follows.

using Caliburn.Micro;
public abstract class VisibleObjectEntityViewModel : Screen {
}

public void SetBold() {
   _entity.FontWeight = FontWeights.Bold.ToOpenTypeWeight();
   NotifyOfPropertyChange("Entity");
}

Hope this helps.

Back to Top
Siyfion View Drop Down
Groupie
Groupie
Avatar

Joined: 22-Mar-2012
Location: Bristol, UK
Posts: 47
Post Options Post Options   Quote Siyfion Quote  Post ReplyReply Direct Link To This Post Posted: 19-Apr-2012 at 1:13am
I thought that the entities / entity properties in DevForce already had some form of change notifications built in? Otherwise if you ever bind a view directly to an entity you'll have to add the NotifyOfPropertyChanged() into the generated code for every property..?
Back to Top
mgood View Drop Down
IdeaBlade
IdeaBlade
Avatar

Joined: 18-Nov-2010
Location: Emeryville, CA
Posts: 583
Post Options Post Options   Quote mgood Quote  Post ReplyReply Direct Link To This Post Posted: 19-Apr-2012 at 11:54am
Simon,
That is correct. Denis, I think there's a bug somewhere.
Back to Top
DenisK View Drop Down
IdeaBlade
IdeaBlade


Joined: 25-Aug-2010
Posts: 715
Post Options Post Options   Quote DenisK Quote  Post ReplyReply Direct Link To This Post Posted: 19-Apr-2012 at 1:22pm
Hi Simon (and Marcel),

I was almost sure this was a bug until I noticed that you haven't attached (added) the entity to the EntityManager. The EntityManager is the one that's responsible for firing the various property change notification. Sorry for giving out the wrong info.

One more note is that I noticed your MatrixEntity has an Id that is a foreign key as well as a primary key and it's set to StoreGeneratedPattern.Identity. You need to set this to StoreGeneratedPattern.None as the EntityManager will not generate a temp id for a foreign key and it will throw an exception upon adding MatrixEntity.


Edited by DenisK - 19-Apr-2012 at 1:25pm
Back to Top
Siyfion View Drop Down
Groupie
Groupie
Avatar

Joined: 22-Mar-2012
Location: Bristol, UK
Posts: 47
Post Options Post Options   Quote Siyfion Quote  Post ReplyReply Direct Link To This Post Posted: 20-Apr-2012 at 1:24am
Thanks for clearing that up Denis, so you're saying that if I attach the entity to the EntityManager before I bind to it, it should get the notification changes? I'll give it a go!

Also, thanks for the heads up on the Id property, I have no idea how I've managed that, it's certainly not a setting that I've changed myself!
Back to Top
Siyfion View Drop Down
Groupie
Groupie
Avatar

Joined: 22-Mar-2012
Location: Bristol, UK
Posts: 47
Post Options Post Options   Quote Siyfion Quote  Post ReplyReply Direct Link To This Post Posted: 20-Apr-2012 at 2:43am
Yup, nail-on-head there Denis! After changing the edmx diagram to ensure that the StoreGeneratedPattern was set to None, and adding the "dummy" entity to the EntityManager, I can confirm that it works as-expected! ;)
Back to Top
 Post Reply Post Reply

Forum Jump Forum Permissions View Drop Down