问题
Im creating an App and I have a header that its the same for all pages (a footer as well, but that one ill create using the app bar).
My question is, what's the best way to do this if I dont want to repeat the header (code it) in every page.
Thank you.
回答1:
The best was to do this is create the following:
- UserControl for the Header
- UserControl for the Footer
- Everything Page or UserControl should show these items.
回答2:
Look at templating your project so that you can have multiple views and and multiple regions
I would also look at Prism: http://msdn.microsoft.com/en-us/library/gg406140.aspx
回答3:
Depends what you use as header and footer, if it is a simple text then you could use the default page templates and Bind the text to a static resource defined in the App.Xaml, if it is more complex then you could create a user control as suggested. You could create animations too and play this when your page is displayed.
Static resource in App.Xaml as an Application.Resource
:
<Application.Resources>
<sys:String x:Key="applicationTitle">Your Title!</sys:String>
</Application.Resources>
You need to add this namespace to the App.Xaml too :
xmlns:sys="clr-namespace:System;assembly=mscorlib"
Or you could use MVVM too to create a View and a ViewModel for the header. If you are new to MVVM then take a look at Galasofts MVVM light.
GalaSoft MVVM
来源:https://stackoverflow.com/questions/8930580/windows-phone-header-same-for-all-pages