Last active
January 2, 2021 18:02
-
-
Save jbasinger/991ea0d63661430fe94cd293055001f9 to your computer and use it in GitHub Desktop.
Blazor Code Snippet Components
This file contains 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
<pre class="code"><code class="@Language"> | |
@ChildContent | |
</code></pre> | |
@code { | |
[Inject] private IJSRuntime _js { get; set; } | |
[Parameter] public RenderFragment ChildContent { get; set; } | |
[Parameter] public string Language { get; set; } = "csharp"; | |
protected override async Task OnAfterRenderAsync(bool firstRender) | |
{ | |
await _js.InvokeVoidAsync("highlightSnippet"); | |
} | |
} |
This file contains 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
<body> | |
<app>Loading...</app> | |
<div id="blazor-error-ui"> | |
An unhandled error has occurred. | |
<a href="" class="reload">Reload</a> | |
<a class="dismiss">🗙</a> | |
</div> | |
<script src="//cdnjs.cloudflare.com/ajax/libs/highlight.js/10.4.1/highlight.min.js"></script> | |
<script src="//cdnjs.cloudflare.com/ajax/libs/highlight.js/10.4.1/languages/csharp.min.js"></script> | |
<script src="//cdnjs.cloudflare.com/ajax/libs/highlight.js/10.4.1/languages/css.min.js"></script> | |
<script> | |
window.highlightSnippet = function(){ | |
document.querySelectorAll('pre code').forEach((el)=>{ | |
hljs.highlightBlock(el); | |
}); | |
} | |
</script> | |
<script src="_framework/blazor.webassembly.js"></script> | |
</body> |
This file contains 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
<CodeSnippet> | |
public class PersonModel | |
{ | |
public int Id { get; set; } | |
[Display(Name="First Name")] | |
public string Name { get; set; } | |
public string City { get; set; } | |
public string State { get; set; } | |
[BlazinHeaderFormat("{0:C}")] | |
public int Salary { get; set; } | |
[BlazinHeaderIgnore] | |
public string ThisColumnWontEvenShowUp { get; set; } | |
} | |
</CodeSnippet> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment