Quantcast
Channel: Active questions tagged blazor - Stack Overflow
Viewing all articles
Browse latest Browse all 4839

How do I call method in Blazor component from XAML code?

$
0
0

Is there any way how to call blazor method (ShowSomething()) from xaml code (Button_clicked())?

for example:

@page "/"<h1>Hello, world!</h1><h1>@if (testingString is not null)    {        @testingString    }    else    {<h2>nothing is loaded</h2>    }</h1><button @onclick="ShowSomething">Update from Blazor</button>@code{    public string testingString { get; set; }    public void ShowSomething()    {        testingString = "Showing something";    }}

MainPage.xaml.cs:

 public partial class MainPage : ContentPage {     public MainPage()     {         InitializeComponent();     }     TestBackdrop.Pages.Index index = new TestBackdrop.Pages.Index();     private void Button_clicked(object sender, EventArgs e)     {         index.ShowSomething();         index.testingString = "experiment number 2";     } }

and xaml page is simple grid with webview and button:

I tried to use StateHasChanged() but then I got

The render handle is not yet assigned

Is there any way to do it?

Thank you.


Viewing all articles
Browse latest Browse all 4839

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>