View not updated

Topics: Prism v2 - WPF 3.5
May 4, 2010 at 4:44 PM

Hi, I made a moudle with two views(ViewA, ViewB)  displayed in two different regions in the window.

ViewA has a texblox on it while ViewB has button on it.

When I click the Button on viewB, I would like to update the textblock on ViewA.

I have routed the event to make the flow which seems correct when I step through the code. (ViewA, ViewB, ViewAPresenter, ViewBPresenter, ViewController). The ViewBController's constructor linked all the event together

public ViewBPresenter(IUnityContainer container, 
            IViewB view, 
            IViewController viewcontroller)
        {
            this.View = view;
            this.container = container;
            this.controller = viewcontroller;

            this.View.SearchCriteriaSubmitted += delegate(object sender, DataEventArgs e)
            {
                SearchCriteriaSubmitted(sender, e);
            };

            this.SearchCriteriaSubmitted += new EventHandler>(this.OnSearchCriteriaSubmitted);

                    }

private void OnSearchCriteriaSubmitted(object sender, DataEventArgs e)
        {
            controller.OnSearchCriteriaSubmitted(e.Value);
        }

However, while I can see the texblock on ViewA is updated correctly when I step through the code in TextBlockToUpdate, the texblock is not updated on the user interface.

public partial class ViewA    {
        public ViewA()
        {
            InitializeComponent();
        }
         
        public string TextBlockToUpdate
        {
            get
            {
                return this.TextBlockToUpdate.Text;
            }
            set
            {
                this.TextBlockToUpdate.Text = value;
                
            }
        }

        
 

I try to follow the ViewInjection quick start. However, the viewinjection sample is based on three views while my scenairo is based on two views.

Is there an example about two views within the same module to updaet each other?

What changes do I need to make to my code to get the textblock updated?

Thanks

May 6, 2010 at 2:16 PM

Hi,

I have put together a small sample showing how to communicate two views when using MVP which you can download from here. It is a very simple scenario, and I omitted the controller, but I hope you can get the basic ideas. Take into account that to keep the sample simple, I did not create any interfaces (for the views, presenter, etc). However, that is a recommended approach in your application, as not being tied to a particular implementation increases the testability.

Please let me know if this helps.

Damian Schenkelman
http://blogs.southworks.net/dschenkelman