Methods and Statements
Community Technology Preview (CTP)
This article covers the CTP version of Radzen Blazor Studio. Please note that features can change during the CTP period. Bugs and performance issues are expected.
Methods are the bread and butter of every Blazor application. You use them to query a database, respond to user actions, handle Blazor lifecycle events and more.
You can manage methods and their statements of your Blazor components or C# classes via Radzen Blazor Studio’s Methods design mode.
To access Methods design mode open a
.cs file and click the corresponding button in the design canvas toolbar.
Radzen Blazor Studio will display a dropdown with all methods that are accessible are accessible from the current class / component.
Radzen Blazor Studio lists methods that may be defined in other files (when you use partial classes for example).
Methods consist of statements - basically one or more lines of code that perform certain task. For example assignments, loops, if checks, try/catch blocks, method invocations et. al.
Radzen Blazor Studio allows you to visually edit a method by adding or removing statements to it.
Invoke a method and assign its result to a field
Invoking a service method and assigning its result to a field is a common task in Blazor development. Here is how to do it with Radzen Blazor Studio.
- Open a
.razorfile and enter Methods design mode.
OnInitializedAsyncfrom the Override dropdown. It lists all Blazor lifecycle methods which are not yet overridden by your component.
- Click the + button below the start box and pick Invoke from the popup.
- Select the Method you wish to invoke. Start typing its name and Radzen Blazor Studio will suggest you the available options - all methods of the injected services as well as the own methods of the current file.
- If the chosen method returns a value you can set Result as well. You can either pick an existing field or property to assign the result to or create a new one.
Radzen Blazor Studio provides built-in support for the following statements.
Assign values to existing fields, properties or variables.
Declare method variables to store method or computation results.
Invoke own methods or methods of properties or fields.
NavigationManager to navigate to a page. A page is a Blazor component with a
Return to the previous page.
Create a C#
Display a notification message. Uses the Radzen.Blazor library’s
Display a dialog. Uses the Radzen.Blazor library’s
Closes the current dialog. Uses the Radzen.Blazor library’s
Open Context Menu
Opens a context menu. Uses the Radzen.Blazor library’s
Opens a tooltip. Uses the Radzen.Blazor library’s
Any other C# statement.
Important: statements that require the
Radzen.Blazorcomponent library are available only in applications that have Radzen.Blazor correctly installed and the required services registered.