Disable iOS Swipe gestures in .NET 8.0 Maui

Aiko 20 Reputation points
2025-02-17T10:16:58.5333333+00:00

Hi,

I am new to .Net Maui and trying to disable the iOS Swipe gestures in my .NET 8.0 Maui App.

I followed this example for Shell,:

https://learn.microsoft.com/en-us/answers/questions/1143556/how-to-disable-the-swipe-back-in-ios-using-net-mau

but my MauiProgram.cs can't find the class CustomShellRenderer.

shellRenderer

Am I missing anything to include the iOS classes here?

To reproduce, just create a new NET 8 Maui App, insert the CustomShellRenderer.cs in the Plattforms/iOS folder and add the code in the MauiProgram.cs as shown in the linked question.

Developer technologies .NET .NET MAUI
0 comments No comments
{count} votes

Accepted answer
  1. Wenyan Zhang (Shanghai Wicresoft Co,.Ltd.) 36,436 Reputation points Microsoft External Staff
    2025-02-18T07:09:01.76+00:00

    Hello,

    You could open the CustomShellRenderer.cs file and see if the namespace is Test1.Platforms.iOS, and then add the condition on MauiProgram.cs .

    #if IOS
    using Test1.Platforms.iOS;// the namespace may be this 
    #endif
    

    If you still have the problem, you could configure filename-based multi-targeting, see Configure .NET MAUI multi-targeting - .NET MAUI | Microsoft Learn

    For example:

    <!-- iOS -->
    <ItemGroup Condition="$(TargetFramework.StartsWith('net8.0-ios')) != true">
      <Compile Remove="**\*.iOS.cs" />
      <None Include="**\*.iOS.cs" Exclude="$(DefaultItemExcludes);$(DefaultExcludesInProjectFolder)" />
    </ItemGroup>
    

    There is also another way, you could remove the CustomShellRenderer.cs in the Plattforms/iOS folder, and then add the condition, copy the code on MauiProgram.cs directly.

    For example:

    #if IOS
    public class CustomShellRenderer : ShellRenderer
    {
       ...// your code
    }
     
    public class CustomSectionRenderer : ShellSectionRenderer
    {
       ...
    }
    #endif
    
     
    

    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.

    1 person found this answer helpful.

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.