0

I have several classes derived from a base class. VideoAsset, ImageAsset, etc. Lets say each has a different sort of header xaml.

I have two screens, one with a collectionview (that displays different xaml based on asset type) and one that shows details of that asset.

I have the collectionview working so it uses different xaml to display each asset type.

ItemTemplate="{StaticResource assetDataTemplateSelector}"   

Easy. The issue is with the detail page. I did have a separate contentPage for each class (and when you clicked the collectionview it passed the asset to the relevant sort of contentpage) but now I think I should really have one ContentPage and display different bits of xaml depending on the class it is binding to (video header for video asset, etc). The header part of the page would reference a TemplateSelector as above but I don't see how that can be implemented.

Question is, how would I do this for a ContentPage (not a list/collectionview)? Declare all the bits in the pages Resourcedictionary? Is it TemplatedPage, DataTemplate or UserControl? No one else asking the same question on SO really gets a proper answer.

Edit: Added some more detail.

ThirdPrize
  • 194
  • 1
  • 13
  • A ContentPage is simply a "wrapper" around a view, so that it can behave as a page (fill the screen). Don't try to do this to the ContentPage itself. First, decide what navigation you want. Maybe your app should use TabbedPage or Shell. Second, if you have bits of xaml that you want to be dynamic, then make that part of the XAML a [`ContentView`](https://docs.microsoft.com/en-us/xamarin/xamarin-forms/user-interface/layouts/contentview), with a [`DataTemplateSelector`](https://docs.microsoft.com/en-us/xamarin/xamarin-forms/app-fundamentals/templates/data-templates/selector). Google for examples – ToolmakerSteve Aug 15 '21 at 20:50
  • @ThirdPrize Not sure what you want to do, so can not provide suggestion or code for you, you can post some code and describe your problem here. – Cherry Bu - MSFT Aug 16 '21 at 02:29
  • @CherryBu-MSFT added some more detail. It is really just how do you custoimise a contentpage based on the type of the class it is binding to. Like DataTemplate but for a page rater than a listview. – ThirdPrize Aug 16 '21 at 09:33
  • AFAIK, it doesn't make any sense to do it "to the page". Rather you customize "views", that you add to a page. Add to question one of the detail pages you made, and indicate which part(s) of it you want to be template driven. If you really want to template the entire page, then do `...`. And template the ``. But consider instead ``. I mean, break the page into several content views, each of which you can template. Inbetween them, add any "fixed" content. – ToolmakerSteve Aug 16 '21 at 09:56
  • @ToolmakerSteve I suppose you are right. – ThirdPrize Aug 16 '21 at 14:47
  • @ThirdPrize As ToolmakerSteve said that, you can try to use ContentView to display different data. – Cherry Bu - MSFT Aug 18 '21 at 07:56

0 Answers0