XAML markup extensions help

StephenH 86 Reputation points
2022-12-01T13:28:24.2+00:00

I am using shell ...
I want to offer a different view based on form factor in the shell itself

I have looked at LOTS of people using OnIdiom for this but now with a ContentTemplate ..

Any help is appreciated ..

localPhone and localTablet are namespaces

    xmlns:localPhone="clr-namespace:MAUIFieldService.Views.Phone"  
    xmlns:localTablet="clr-namespace:MAUIFieldService.Views.Tablet"  

Here is the code ..

    <FlyoutItem Title="Work to do"   
                  StyleClass="MenuItemLayoutStyle">  
        <FlyoutItem.Icon>  
            <FontImageSource FontFamily="FA6ProReg400"  Glyph="{x:Static models:FA6ProRegular400.PersonDigging}" Size="Title" Color="Black"/>  
        </FlyoutItem.Icon>  
        <ShellContent Route="AssignmentsView"   
                      ContentTemplate="{OnIdiom DataTemplate localPhone:AssignmentsView,  
                                Phone=DataTemplate localPhone:AssignmentsView,   
                                        Tablet=DataTemplate localTablet:AssignmentsView}">  
  
        </ShellContent>  
    </FlyoutItem>  

Here is the error ...
266077-image.png

Any help you can offer is appreciated ...

.NET MAUI
.NET MAUI
A Microsoft open-source framework for building native device applications spanning mobile, tablet, and desktop.
3,594 questions
{count} votes

Accepted answer
  1. Wenyan Zhang (Shanghai Wicresoft Co,.Ltd.) 32,386 Reputation points Microsoft Vendor
    2022-12-02T07:31:13.697+00:00

    Hello @StephenH ,

    I thought the default option was to be specified first like shown in the docs ?

    Yes, you can set the default option. The key point is that the {} is missing. You can use OnIdiom<T> like the following code:

     <ShellContent  
                ...  
                ContentTemplate="{OnIdiom {DataTemplate XXX}, Phone={DataTemplate localPhone:XXX},Desktop={DataTemplate XXX},Tablet={DataTemplate localTablet:XXX}}"  
                />  
    

    Best Regards,
    Wenyan Zhang


    If the answer is the right solution, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".
    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.


0 additional answers

Sort by: Most helpful

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.