Created
June 6, 2022 15:51
-
-
Save SigurdJanson/fed01c59cb3d088ba5210215eb1a4da2 to your computer and use it in GitHub Desktop.
Blazor RenderFragments
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // TYPE 1 | |
| protected RenderFragment RenderThis = @<span title = "I was a render fragment, once" class="fragged"> | |
| You can use me many times without per-component overhead | |
| </span>; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <p> | |
| @RenderThis | |
| </p> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // TYPE 1 | |
| protected RenderFragment RenderThis = @<span>Use me many times</span>; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // TYPE 2 - Arrow Function Delegate | |
| private RenderFragment RenderWelcomeInfo = __builder => | |
| { | |
| <p class="welcome">Welcome to your new app!</p><p>New</p> | |
| }; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // TYPE 3: Parametrized Arrow Function Delegate | |
| private RenderFragment<Source> RenderLiteratureSource = LibSource => __builder => | |
| { | |
| <li class="source"> | |
| <a [email protected]> | |
| <span class="stitle">@LibSource.Title</span> | |
| </a> | |
| </li> | |
| }; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // TYPE 4: Method | |
| private RenderFragment RenderNow(string ClassName) | |
| { | |
| if (ClassName == "time") | |
| { | |
| return @<p class="now">⏲ @DateTime.Now.ToString("T")</p>; | |
| } | |
| else if (ClassName == "date") | |
| { | |
| return @<p class=@ClassName>📆 @DateTime.Now.ToShortDateString()</p>; | |
| } | |
| return @<p>I cannot show you date or time because I wasn't given a format that I understand.</p>; | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment