Posts

Showing posts from June, 2022

Datetime Blazor Component with dynamic Styling

Image
  I wanted to build a component that would utilize a dynamic class for styling.  I came across a nice component that displays the date and time and this post is how I created a Blazor component from it that uses a dynamic style.  We want to be able to do this so we are not changing the component code everything we using.  This is very helpful if the component is part of a UI library. The code in this post was built on .Net 6 using Visual Studio 2022 Project break down Basic control The first step was to just build the control as part of a regular page.  The index page was used.  The HTML is fairly straight forward:           <div class="datetime">                <div class="time">@DateTime.Now.ToShortTimeString()</div>                <div class="date">@DateTime.Now.ToLongDateString()</div>           </div> I am just using the DateTime function to generate both the date and the time.  We can use the ToString formatting to