Loading...
Loading...
Create responsive Blazor applications using Media Query component. Trigger when user needs responsive layouts, breakpoint-based rendering, screen size adaptation, multi-device support, or needs to conditionally render components based on device type. Essential for building adaptive UIs that work across mobile, tablet, and desktop devices.
npx skill4agent add syncfusion/blazor-ui-components-skills syncfusion-blazor-media-query@using Syncfusion.Blazor
<SfMediaQuery @bind-ActiveBreakPoint="currentBreakpoint"></SfMediaQuery>
<h3>Current Breakpoint: @currentBreakpoint</h3>
@if (currentBreakpoint == "Small")
{
<p>You are viewing on a mobile device</p>
}
else if (currentBreakpoint == "Medium")
{
<p>You are viewing on a tablet</p>
}
else
{
<p>You are viewing on a desktop</p>
}
@code {
private string currentBreakpoint { get; set; }
}Small → Vertical row layout, hide non-essential columns
Medium → Adaptive mode enabled
Large → Horizontal layout, all columns visibleSmall → Collapse navigation to hamburger menu
Large → Show full navigation barSmall → 1-column layout
Medium → 2-column layout
Large → 3-column layoutMainLayout → Provides activeBreakpoint to all pages
Child Pages → Use CascadingParameter to access breakpoint
Result → Entire app responds to screen size changes| Property | Type | Description |
|---|---|---|
| string | The currently matching breakpoint name (Small, Medium, Large, or custom) |
| List<MediaBreakpoint> | Custom breakpoints with name and media query string |
<SfMediaQuery @bind-ActiveBreakPoint="bp"></SfMediaQuery>
@if (bp == "Small")
{
<MobileLayout />
}
else if (bp == "Medium")
{
<TabletLayout />
}
else
{
<DesktopLayout />
}<SfMediaQuery @bind-ActiveBreakPoint="bp"></SfMediaQuery>
@{
var pageSize = bp == "Small" ? 10 : 25;
var allowPaging = bp != "Small";
}
<SfGrid PageSettings="@new GridPageSettings { PageSize = pageSize }">
...
</SfGrid><SfMediaQuery @bind-ActiveBreakPoint="bp"></SfMediaQuery>
@if (bp == "Small")
{
<button @onclick="ToggleMenu">☰ Menu</button>
}
else
{
<nav>Full Navigation Bar</nav>
}