Connecting two parts without breaking loose coupling

Scenario: Part A has a listbox with items in it. Part B has a button in it. When you push the button in Part B, I want some action to be performed that requires knowledge of the currently selected list box item.

My current thought is to fire a notification from Part B indicating that the button was pushed, which can then be listened to by Part A. I don't know if this works (I've been doing a lot of notifications on other platforms lately, so my knowledge is bleeding over a bit) so I'd like some thoughts on this.

Thanks!

[547 byte] By [KevinHoffman] at [2008-2-7]
# 1

This is one of the possible scenarios (BTW, do you really need to have this button on separate PartView from the ListBox ? )

PartA declares a ComponentProperty visible to the PartAView. PartAView updates this property when ListBox selection changes.

PartB declares ComponentCommand that PartBView calls when the button is pushed.

PartB also declares ComponentNotification visible to other parts.

PartA subscribes for this ComponentNotification.

When the button on PartBView is pushed, ComponentCommand handler on PartB raises the ComponentNotification that can then be intercepted by PartA. PartA checks the value of its ComponentProperty (currently selected ListBoxItem).

If PartB needs to send more information to PartA when button was clicked (rather than a mere notification) you can use ComponentDataPublisher instead of ComponentNotification. You can also check this post for additional information.

AlexBulankou at 2007-10-3 > top of Msdn Tech,.NET Development,Acropolis...
# 2
PartB can't get a reference to PartA and PartA can't get a reference to PartB. If you know of the code to allow this, please let me know. Parts only know how to find their children and nothing else (from what I can tell from the reference)
KevinHoffman at 2007-10-3 > top of Msdn Tech,.NET Development,Acropolis...
# 3

Hmm, that's right sorry I forgot :-)
Well in this case you can declare ComponentCommand on PartA and ComponentNotification on PartB and have the ParentPart route the notifications.
Since ParentPart is the parent for PartA and PartB it can access its children:


void MethodInParentPart(){
PartA partA = (PartA)((PartNavigationItem)NavigationManager.FindItemByName("PartA")).AssociatedPart;
IPartAContract contractA = partA.GetContract<IPartAContract>();

PartB partA = (PartB)((PartNavigationItem)NavigationManager.FindItemByName("PartB")).AssociatedPart;
IPartBContract contractB = partB.GetContract<IPartBContract>();

contractB.ButtonPushedNotification.NotficationFiredFromPartB+=<subsribe for notification from PartB>

}

void NotficationFiredFromPartB()
{
contractA.Command.Execute();
}

AlexBulankou at 2007-10-3 > top of Msdn Tech,.NET Development,Acropolis...
# 4
What I ended up doing was having the parent listen to notifications from child A and then fire a notification down into child B when it occurs.
KevinHoffman at 2007-10-3 > top of Msdn Tech,.NET Development,Acropolis...

.NET Development

Site Classified