简体   繁体   中英

How do I make a content control accessible to multiple WPF windows?

I have a WPF application that uses multiple windows. I have a ContentControl defined for one window, and I would like to be able to use it in the other windows as well.

Right now, my Content Control is defined in the xaml file for one of my windows.

How should I define this content control so that I may access it from all the other windows?

Thanks in advance!

You could declare it public by using the x:FieldModifier attribute:

<ContentControl Name="myControl" x:FieldModifier="Public">
...

However, I wouldn't recommend doing that... instead, you should expose the content itself, not the ContentControl . You can expose it through a public property, or pass it as a constructor parameter to other windows

Make it into a usercontrol.

In Blend it's as easy as selected the control, right clicking and selecting "make into usercontrol" or something similar.

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