简体   繁体   中英

How to implement a WPF Navigation Control presenting Frames of various derived types, all using UserControl as a base

So I have a scenario where I want to implement a WPF NavigationControl derived from UserControl. On that NavigationControl I have two requirements, handling a history for back/forward navigation (simple enough) and being able to Present any control deriving from the type NavigationFrameBase visually. NavigationFrameBase, also deriving from UserControl may be presented in many forms as multiple controls will inherit from this type, but the NavigationFrameBase should provide a form of notification to the NavigationControl to inform it that the user interacting with the content of a type derived from NavigationFrameBase has requested a Navigate operation, allowing the NavigationControl to present a new NavigationFrameBase.

My issues are two fold:

  • What is the best way to design NavigationControl in order to contain an instance of NavigationFrameBase it will present
  • What is the proper way in WPF to handle the child->parent request system? Routed/Attached events seem to be right, but I could see a mediator pattern serving the same function.

It depends on how you expect the communication between the parent and children to occur. If it's simply a matter of the NavigationControl listening for events and reacting then the simple event handling pattern would work.

However, if you need the NavigationControl to affect the NavigationFrames (eg to disable/enable or in the case of a drop-down menu you'd need to close any open drop-downs when another opens, etc.) or to allow one NavigationFrame to affect a sibling then you would need to use a mediator pattern, or expose callback methods on the NavigationFrameBase for handling those actions.

Without knowing more about your expected use cases it's hard to give you more specifics than that.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM