如何将 MudIcon 字符串绑定到 Mud Icon 组件

vis*_*ter 2 icons mudblazor

<MudIcon Icon="@inboxIcon" Color="Color.Primary" />
Run Code Online (Sandbox Code Playgroud)
@code{

   // here this Icon string is coming from database
   
private string inboxIcon = "Icons.Material.Filled.Inbox"; 

}
Run Code Online (Sandbox Code Playgroud)

上面的代码没有显示任何图标。如何绑定这个图标字符串?

小智 5

你快到了。试试这样:

<MudIcon Icon="@inboxIcon" Color="Color.Primary" />


@code{

   // here this Icon string is coming from database
   
private string inboxIcon = MudBlazor.Icons.Material.Filled.Inbox; 

}
Run Code Online (Sandbox Code Playgroud)

命名空间Icons中的 会自动转换为字符串。