Print Page | Close Window

Bindings don't seem to update..?

Printed From: IdeaBlade
Category: Cocktail
Forum Name: Community Forum
Forum Discription: A professional application framework using Caliburn.Micro and DevForce
URL: http://www.ideablade.com/forum/forum_posts.asp?TID=3394
Printed Date: 21-Sep-2025 at 12:20am


Topic: Bindings don't seem to update..?
Posted By: Siyfion
Subject: Bindings don't seem to update..?
Date 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 - 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 - uploads/1418/VisualEntityMappingTest.rar

If someone could take a look and point me in the right direction, it'd be much appreciated!



Replies:
Posted By: JohnBloom
Date 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


Posted By: JohnBloom
Date 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


Posted By: DenisK
Date 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.



Posted By: Siyfion
Date 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..?


Posted By: mgood
Date Posted: 19-Apr-2012 at 11:54am
Simon,
That is correct. Denis, I think there's a bug somewhere.


Posted By: DenisK
Date 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.


Posted By: Siyfion
Date 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!


Posted By: Siyfion
Date 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! ;)



Print Page | Close Window