views:

836

answers:

3

Any ideas on how i get MVP working with Silverlight? How Do I get around the fact there is no load event raised?

This the view I have:

    public partial class Person: IPersonView
    {
        public event RoutedEventHandler Loaded;

        public Person()
        {
            new PersonPresenter(this);

            InitializeComponent();
        }

        public Person Person
        {
            set { Person.ItemsSource = value; }
        }
    }

And my presenter:

 public class PersonPresenter
    {
        private readonly IPersonView _view;
        private readonly ServiceContractClient _client;

        public PersonPresenter(IPersonView view)
        {
            _client = new ServiceContractClient();

            _view = view;
            WireUpEvents();
        }

        private void WireUpEvents()
        {
            _view.Loaded += Load;
        }

        private void Load(object sender, EventArgs e)
        {
            _client.GetPersonCompleted += Client_GetPerson;
            _client.GetPersonAsync();
        }

        private void Client_GetPerson(object sender, GetPersonCompletedEventArgs e)
        {
            _view.Person= e.Result;
        }
    }

Nothing happened for me as the Loaded event dont seem to get called, how do i get around this?

+1  A: 

I believe the loaded event gets called when the control has been initialized, loaded, rendered and ready for use. This means that as long as you don't place it inside a visible container (so that it is rendered), the loaded event won't be risen.

Santiago Palladino
+3  A: 

Tim Ross has a good introduction to Silverlight MVP implementation, with source code.

ANaimi
Yeah that what i ended up using in the end
Dan
A: 

You may consider using MVC# - a Model View Presenter framework with Silverlight 2.0 support.

Oleg Zhukov