开发者

Best way to call back/noftify parent page of an event?

In a Silverlight 3.0 app, there is a shell page that serves as the navigation piece for a number of child controls and other Silverlight pages. The Silverlight pages are included in the shell page via the Frame object (). The pages are rotated dynamically via the code-behind file, so there isn't a direct reference to them in the xaml.

How can these dynamically included pages call back to the shell page? We are currently using events to communicate from the included user controls, but these are known events that we can subscribe to in x开发者_开发问答aml...so if suggesting events, please include concrete examples.

TIA.


If you are creating each child control from the parent page, you might be able to use delegates to accomplish this. Very generic example:

public delegate void FunctionDelegate(string ChildControlName);

In the parent container class:

    public FunctionDelegate EventFunc;

In the parent container constructor:

        EventFunc = DoSomeAction;

Pass EventFunc to the child object and call when appropriate.


I would recommend using Prism developed by the Patterns and Practices Team.

Prism (through the EventAggregator) allows you to push notifications from any source out to listeners of the event you have specified. It's rather cool.

  • MSDN Article: http://msdn.microsoft.com/en-us/library/cc707867.aspx
  • Patterns and Practices Site: http://www.codeplex.com/CompositeWPF/

This is a video about communicating between views through Prism: http://channel9.msdn.com/posts/akMSFT/Creating-a-modular-application-using-Prism-v2-Screencast-44--Decoupled-Communication/

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜