Silverlight 2和MVP模式
时间:2020-03-06 14:44:48 来源:igfitidea点击:
关于我如何使MVP与Silverlight协同工作的任何想法?我如何解决没有引发负载事件的事实?
这个观点我有:
public partial class Person: IPersonView
{
public event RoutedEventHandler Loaded;
public Person()
{
new PersonPresenter(this);
InitializeComponent();
}
public Person Person
{
set { Person.ItemsSource = value; }
}
}
而我的主持人:
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;
}
}
由于Loaded事件似乎没有被调用,对我来说什么都没有发生,我该如何解决呢?
解决方案
我相信在控件已被初始化,加载,呈现并准备使用时,将调用load事件。这意味着只要我们不将其放置在可见的容器中(以便呈现),就不会引发已加载的事件。
Tim Ross通过源代码很好地介绍了Silverlight MVP实现。
我们可以考虑使用MVC#-具有Silverlight 2.0支持的Model View Presenter框架。
奥列格·朱可夫(Oleg Zhukov)

