I am trying to use Telerik Blazor's MediaQuery at the base page. That page, for me is, MainLayout.razor
.
First, I separated the code-behind for the MainLayout
and had to introduce a base class for my properties as MainLayout
already inherits LayoutComponentBase
:
MainLayout.razor
@using DA.BrrMs.Portal.Blazor.Helpers
@inherits MainLayoutModel
@layout TelerikLayout
<TelerikMediaQuery Media="@WindowBreakPoints.ExtraSmall" OnChange="@(matches => IsExtraSmall = matches )"/>
<TelerikMediaQuery Media="@WindowBreakPoints.Small" OnChange="@(matches => IsSmall = matches )"/>
<TelerikMediaQuery Media="@WindowBreakPoints.Medium" OnChange="@(matches => IsMedium = matches )"/>
<TelerikMediaQuery Media="@WindowBreakPoints.Large" OnChange="@(matches => IsLarge = matches )"/>
<TelerikMediaQuery Media="@WindowBreakPoints.ExtraLarge" OnChange="@(matches => IsExtraLarge = matches )"/>
<Header @bind-StateCssClass="@NavMenuCssClass"></Header>
<div class="main">
<div class="sidebar @NavMenuCssClass">
<NavMenu />
</div>
<div class="container-fluid px-2">
@Body
</div>
</div>
MainLayout.razor.cs
using DA.BrrMs.Portal.Blazor.Base;
namespace DA.BrrMs.Portal.Blazor.Shared
{
public class MainLayoutModel : BaseLayout
{
protected string NavMenuCssClass { get; set; }
}
}
BaseLayout.cs
using Microsoft.AspNetCore.Components;
namespace DA.BrrMs.Portal.Blazor.Base
{
public class BaseLayout : LayoutComponentBase
{
protected bool IsExtraSmall { get; set; }
protected bool IsSmall { get; set; }
protected bool IsMedium { get; set; }
protected bool IsLarge { get; set; }
protected bool IsExtraLarge { get; set; }
}
}
With this done, at very late hours, I realized there is no code level link between a MainLayout
and any other page and I cannot access the IsSmall
property in my dashboard page. I need to change the layout itself is screen is small or less for my mobile clients and that's another reason for me doing this at MainLayout level
Any proper way to accomplish this?