Radzen Components from Razor Class Library

Hello Team,

I would like to create my own components in a razor class library, based on Radzen.

Assuming I have a MyLabel.razor with simply one RadzenLabel.
To access to all the properties and methods of the RadzenLabel, I have to explicitly declare them all as Parameters.

<RadzenLabel Text="@Text"></RadzenLabel>

@code
{
    [Parameter]
    public string Text { get; set; } = "";
}

Is there a better way to do this?

I ve tried @inherits and @ref but it didnt help.

Thank you.

Not sure what you’ve tried with @inherits however I can assure you that definitely works. You can check our source code for reference. Not sure about @ref however how it’s related.

If you use composition over inheritance indeed you will need to declare all properties/methods in your custom component.

well, if I create MyLabel.razor like this

@inherits RadzenLabel
<RadzenLabel></RadzenLabel>

and use it somewhere like this

<MyLabel Text="this is my text"></MyLabel>

I dont get any text.

Not sure what’s the markup for, all you need is
@inherits RadzenLabel

I think I get it now.
Using simply the RadzenLabel with @inherits RadzenLabel isnt enough.
Also you dont need to declare the parameters explicitly - as I did before -. Just use @inherits RadzenLabel.
Still you need at least to assign the parameters to each other like Text ="@Text".
I think it doesnt get any better. If if does please let me know.
Thank you :slight_smile:

Inheritance won't work if you use a .razor file. In that case it will override the default rendering of the component and you would need to specify your own properties. However if you create a regular c# class which inherits from RadzenLabel you would inherit the rendering too.

public class MyLabel : RadzenLabel
{
}
1 Like

It does get better. Thank you very much :smiley:
Could I do the same with the NotificationService for example?
I didnt get it to work with the following code:
public class MyNotification : RadzenNotification
public class MyNotificationService : NotificationService
In MainLayout.razor I first added both Elements <MyNotification /> and <RadzenNotification /> for test purposes.
Same in Program.cs with builder.Services.AddScoped<NotificationService>(); and builder.Services.AddScoped<MyNotificationService>();
Only the RadzenService works fine.
So the question is generally how can I make a custom service out of a Radzen Service.
Thank you.

I put my last question in this topic: Custom Services based on Radzen Services

I hope it doesn’t contravene the community guidelines.

@diegodiegoo
Can i ask u an example?

Ex: I need to achive a component that has the input form in question as child of the New RadzenFormField Component. So for example by calling CustomInputText i result with a RadzenInputText inside a RadzenFormField. (the example dont need to be related to this scenario)

Thanks