BlazorPro.BlazorSize 2.0.2

There is a newer version of this package available.
See the version list below for details.
dotnet add package BlazorPro.BlazorSize --version 2.0.2
NuGet\Install-Package BlazorPro.BlazorSize -Version 2.0.2
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="BlazorPro.BlazorSize" Version="2.0.2" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add BlazorPro.BlazorSize --version 2.0.2
#r "nuget: BlazorPro.BlazorSize, 2.0.2"
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
// Install BlazorPro.BlazorSize as a Cake Addin
#addin nuget:?package=BlazorPro.BlazorSize&version=2.0.2

// Install BlazorPro.BlazorSize as a Cake Tool
#tool nuget:?package=BlazorPro.BlazorSize&version=2.0.2

BlazorSize is a JavaScript interop library for Blazor that is used to detect the Browser's current size, change in size, and test media queries.

BlazorSize was designed to allow Razor Components to implement adaptive rendering. Handle mobile/desktop rendering changes at runtime with ease and complement your apps CSS media queries with programmatic work flows.

Add the NuGet package

Package Manager

Install-Package BlazorPro.BlazorSize 

CLI

dotnet add package BlazorPro.BlazorSize 

.csproj

<PackageReference Include="BlazorPro.BlazorSize" Version="2.*" />

Reference the JavaScript interop

Add the JavaScript interop to your application's index.html or _hosts.cshtml

    
    <script src="_content/BlazorPro.BlazorSize/blazorSize.min.js"></script>

Import the namespace

Add a reference to the namespace in your _Imports.razor or at the top of a page.

@using BlazorPro.BlazorSize

Add the MediaQueryList

Add a MediaQueryList to your application's main layout or root. The MediaQueryList is responsponsible for communicating with all MediaQuery components in your app. The MediaQueryList component will consolidate redundant media queries and manage resources so that unused event listeners are disposed of properly.

<MediaQueryList>
    <div class="sidebar">
        <NavMenu />
    </div>

    <div class="main">
        <div class="top-row px-4">
            <a href="http://blazor.net" target="_blank" class="ml-md-auto">About</a>
        </div>

        <div class="content px-4">
            @Body
        </div>
    </div>
</MediaQueryList>

Add a MediaQuery and bind

Using the @bind-Matches directive we can easily bind to a browser's media query and respond to it.

@if (IsSmall)
{
    <WeatherCards Data="forecasts"></WeatherCards>
}
else
{
    <WeatherGrid Data="forecasts"></WeatherGrid>
}

@if (IsMedium)
{
    <span>Medium</span>
}

<MediaQuery Media="@Breakpoints.OnlyMedium" @bind-Matches="IsMedium" />
<MediaQuery Media="@Breakpoints.SmallDown" @bind-Matches="IsSmall" />

@code {
    WeatherForecast[] forecasts;

    bool IsMedium = false;
    bool IsSmall = false;

    protected override async Task OnInitializedAsync()
    {
        forecasts = await Http.GetFromJsonAsync<WeatherForecast[]>("sample-data/weather.json");
    }
}

No-Code Templates

The MediaQuery component can also use templates instead of the @bind directive. Templates are useful for swapping out UI bits when the screen size changes.


<MediaQuery Media="@Breakpoints.SmallDown">
    <Matched>
        <WeatherCards Data="forecasts"></WeatherCards>
    </Matched>
    <Unmatched>
        <WeatherGrid Data="forecasts"></WeatherGrid>
    </Unmatched>
</MediaQuery>

Product Compatible and additional computed target framework versions.
.NET net5.0 was computed.  net5.0-windows was computed.  net6.0 was computed.  net6.0-android was computed.  net6.0-ios was computed.  net6.0-maccatalyst was computed.  net6.0-macos was computed.  net6.0-tvos was computed.  net6.0-windows was computed.  net7.0 was computed.  net7.0-android was computed.  net7.0-ios was computed.  net7.0-maccatalyst was computed.  net7.0-macos was computed.  net7.0-tvos was computed.  net7.0-windows was computed.  net8.0 was computed.  net8.0-android was computed.  net8.0-browser was computed.  net8.0-ios was computed.  net8.0-maccatalyst was computed.  net8.0-macos was computed.  net8.0-tvos was computed.  net8.0-windows was computed. 
.NET Core netcoreapp2.0 was computed.  netcoreapp2.1 was computed.  netcoreapp2.2 was computed.  netcoreapp3.0 was computed.  netcoreapp3.1 was computed. 
.NET Standard netstandard2.0 is compatible.  netstandard2.1 was computed. 
.NET Framework net461 was computed.  net462 was computed.  net463 was computed.  net47 was computed.  net471 was computed.  net472 was computed.  net48 was computed.  net481 was computed. 
MonoAndroid monoandroid was computed. 
MonoMac monomac was computed. 
MonoTouch monotouch was computed. 
Tizen tizen40 was computed.  tizen60 was computed. 
Xamarin.iOS xamarinios was computed. 
Xamarin.Mac xamarinmac was computed. 
Xamarin.TVOS xamarintvos was computed. 
Xamarin.WatchOS xamarinwatchos was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages (7)

Showing the top 5 NuGet packages that depend on BlazorPro.BlazorSize:

Package Downloads
Blazm.Components

A collection of Blazor components

BlazorPro.BlazorSize.UnitTesting

A testing library to provide helper extensions for BlazorSize.

Ozytis.Blazor.ArchitectUI

Blazor layout using architectui

TailBlazor.NavBar

A Blazor navbar component based off TailWindCss. It has the bare minimum styles to function with the option to add your own classes. It's built so it can be fully customizable and reusable.

AutoCore.Web

Package Description

GitHub repositories (1)

Showing the top 1 popular GitHub repositories that depend on BlazorPro.BlazorSize:

Repository Stars
telerik/blazor-ui
A collection of examples related to Telerik UI for Blazor Components: https://www.telerik.com/blazor-ui
Version Downloads Last updated
8.0.0-preview 75 4/15/2024
6.2.2 69,092 8/30/2023
6.2.1 86,005 4/25/2023
6.2.0 40,721 1/6/2023
6.1.2 129,856 2/12/2022
6.1.1 8,172 1/28/2022
6.1.0 22,333 12/1/2021
6.0.0 25,836 11/10/2021
6.0.0-pre2 2,582 10/5/2021
6.0.0-pre 257 8/23/2021
5.0.0 55,419 5/27/2021
5.0.0-pre 1,081 5/25/2021
3.2.1 18,724 3/9/2021
3.2.0 2,122 3/5/2021
3.1.0 60,067 11/30/2020
3.0.0 1,747 11/23/2020
2.3.0 42,745 8/11/2020
2.0.2 20,906 4/21/2020
1.2.2 10,057 1/26/2020
1.2.1 1,100 1/23/2020
1.2.0 1,208 1/22/2020

2.0.0
      Added MediaQueryList & MediaQuery components.
1.2.2
      Fixes initalization issues with Client-Side Blazor
1.2.0
      Full-release