我想知道,是否有可能创建具有多个参数的可重复使用的RenderFragments。有一些Microsoft Docs的示例有1个参数,但没有多个参数。有可能吗?
我想要这样的东西:
@Row("text1", "text2");
@code {
RenderFragment<string, string> Row = (string col1, string col2) => __builder =>
{
<div class="row">
<div class="col-5 align-self-center">
@col1
</div>
<div class="col align-self-center">
@col2
</div>
</div>
}
}
您可以这样做:
@Row(("text1", "text2"))
@code
{
RenderFragment<(string col1, string col2)> Row => value => __builder =>
{
<div class="row">
<div class="col-5 align-self-center">
@value.col1
</div>
<div class="col align-self-center">
@value.col2
</div>
</div>
};
}
更新
@Row(("text1", "text2", Message("This is my message")))
@code
{
RenderFragment<(string col1, string col2, RenderFragment fragnment)> Row => value => __builder =>
{
<div class="row">
<div class="col-5 align-self-center">
@value.col1
</div>
<div class="col align-self-center">
@value.col2
</div>
<div class="col align-self-center">
@value.fragnment
</div>
</div>
};
RenderFragment<string> Message => (message) => __builder =>
{ <h1>@message</h1>;
};
}