I want to call a function in Index.razor under Pages from the right-click context menu.

ichiro kanazawa 80 Reputation points
2023-08-07T23:54:36.3866667+00:00

Thank you for reading my message.

I have a question about the .net maui blazor program.

I was able to display the context menu by right-clicking with reference to the following site.
https://learn.microsoft.com/ja-jp/dotnet/maui/user-interface/context-menu

Next, I would like to call the function defined in Index.razor from OnWebViewGoToRepoClicked()
How should I program it?

Thanks for your cooperation.

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

Accepted answer
  1. Yonglun Liu (Shanghai Wicresoft Co,.Ltd.) 50,126 Reputation points Microsoft External Staff
    2023-08-08T02:39:11.2866667+00:00

    Hello,

    After testing, you could follow these steps to implement this requirement.

    Step 1. Implement singletons and methods that need to be called in Index.razor.

    @code {
        public static Index Instance{ get; private set; }
        public Index()
        {
            Instance = this;
        }
        public void ConsoleTest()
        {
            Console.WriteLine("test");
        }
    }
    

    Step 2. Call ConsoleTest from OnWebViewGoToRepoClicked()

    var i = Pages.Index.Instance;
    i.ConsoleTest();
    

    Best Regards,

    Alec Liu.


    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.