Table of Contents

Interface IBrowserViewportService

Namespace
MudBlazor
Assembly
MudBlazor.dll

Represents a service that serves to listen to browser window size changes and breakpoints.

public interface IBrowserViewportService : IAsyncDisposable
Inherited Members
Extension Methods

Properties

ResizeOptions

Gets the current resize options.

ResizeOptions ResizeOptions { get; }

Property Value

ResizeOptions

Methods

GetCurrentBreakpointAsync()

Get the current breakpoint

Task<Breakpoint> GetCurrentBreakpointAsync()

Returns

Task<Breakpoint>

A task representing the current breakpoint

GetCurrentBrowserWindowSizeAsync()

Get the current size of the window

Task<BrowserWindowSize> GetCurrentBrowserWindowSizeAsync()

Returns

Task<BrowserWindowSize>

A task representing the current browser size

IsBreakpointWithinReferenceSizeAsync(Breakpoint, Breakpoint)

Check if the current breakpoint fits within the reference size

Task<bool> IsBreakpointWithinReferenceSizeAsync(Breakpoint breakpoint, Breakpoint reference)

Parameters

breakpoint Breakpoint

The breakpoint to check

reference Breakpoint

The reference breakpoint (Xs, Sm, Md, Lg,Xl, Xxl)

Returns

Task<bool>

A task representing whether the media size meets the criteria. Returns true if the media size meets the criteria; otherwise, returns false. For example, if the reference size is Sm and the breakpoint is set to SmAndDown, this method will return true.

IsBreakpointWithinWindowSizeAsync(Breakpoint)

Check if the current breakpoint fits within the current window size

Task<bool> IsBreakpointWithinWindowSizeAsync(Breakpoint breakpoint)

Parameters

breakpoint Breakpoint

The breakpoint to check.

Returns

Task<bool>

A task representing whether the media size meets the criteria. Returns true if the media size meets the criteria; otherwise, returns false. For example, if the current window size is Sm and the breakpoint is set to SmAndDown, this method will return true.

IsMediaQueryMatchAsync(string)

Matches if the document currently matches the media query, or false if not.

Task<bool> IsMediaQueryMatchAsync(string mediaQuery)

Parameters

mediaQuery string

A string specifying the media query.

Returns

Task<bool>

A task representing a boolean value that is true if the document currently matches the media query; otherwise, it's false.

SubscribeAsync(IBrowserViewportObserver, bool)

Subscribes an observer to receive notifications of browser window size changes and breakpoints.

Task SubscribeAsync(IBrowserViewportObserver observer, bool fireImmediately = true)

Parameters

observer IBrowserViewportObserver

The observer to subscribe.

fireImmediately bool

Indicates whether the event will fire immediately with the current BrowserWindowSize and Breakpoint information without waiting for changes. When set to true, the event will be fired immediately. When set to false, it will wait for the service to observe any changes before firing the event. The event NotifyBrowserViewportChangeAsync(BrowserViewportEventArgs) won't fire if such Id already exist, for example when you re-subscribe.

Returns

Task

A task representing the asynchronous operation.

SubscribeAsync(Guid, Action<BrowserViewportEventArgs>, ResizeOptions?, bool)

Subscribes a lambda Action<T> with a unique ID to receive notifications of browser window size changes and breakpoints.

Task SubscribeAsync(Guid observerId, Action<BrowserViewportEventArgs> lambda, ResizeOptions? options = null, bool fireImmediately = true)

Parameters

observerId Guid

The unique ID associated with the observer. Use this ID to later UnsubscribeAsync(Guid).

lambda Action<BrowserViewportEventArgs>

The lambda function to subscribe.

options ResizeOptions

The resize options for the observer. When set to null, the global options provided during AddMudServices/AddMudBlazorResizeListener will be used. When specific options are provided, they will be used to observe the changes. The Action<T> won't be invoked if such Id already exist, for example when you re-subscribe. After you pass the options, modifying the instance won't have any effect, including re-subscription, as C# and JS side doesn't support this, you need to UnsubscribeAsync(Guid) and subscribe again.

fireImmediately bool

Indicates whether the event will fire immediately with the current BrowserWindowSize and Breakpoint information without waiting for changes. When set to true, the event will be fired immediately. When set to false, it will wait for the service to observe any changes before firing the event.

Returns

Task

A task representing the asynchronous operation.

SubscribeAsync(Guid, Func<BrowserViewportEventArgs, Task>, ResizeOptions?, bool)

Subscribes a lambda Func<T, TResult> with a unique ID to receive notifications of browser window size changes and breakpoints.

Task SubscribeAsync(Guid observerId, Func<BrowserViewportEventArgs, Task> lambda, ResizeOptions? options = null, bool fireImmediately = true)

Parameters

observerId Guid

The unique ID associated with the observer. Use this ID to later UnsubscribeAsync(Guid).

lambda Func<BrowserViewportEventArgs, Task>

The lambda function to subscribe.

options ResizeOptions

The resize options for the observer. When set to null, the global options provided during AddMudServices/AddMudBlazorResizeListener will be used. When specific options are provided, they will be used to observe the changes. The Func<T, TResult> won't be invoked if such Id already exist, for example when you re-subscribe. After you pass the options, modifying the instance won't have any effect, including re-subscription, as C# and JS side doesn't support this, you need to UnsubscribeAsync(Guid) and subscribe again.

fireImmediately bool

Indicates whether the event will fire immediately with the current BrowserWindowSize and Breakpoint information without waiting for changes. When set to true, the event will be fired immediately. When set to false, it will wait for the service to observe any changes before firing the event.

Returns

Task

A task representing the asynchronous operation.

UnsubscribeAsync(IBrowserViewportObserver)

Unsubscribes an observer from receiving notifications.

Task UnsubscribeAsync(IBrowserViewportObserver observer)

Parameters

observer IBrowserViewportObserver

The observer to unsubscribe.

Returns

Task

A task representing the asynchronous operation.

UnsubscribeAsync(Guid)

Unsubscribes with the specified ID from receiving notifications.

Task UnsubscribeAsync(Guid observerId)

Parameters

observerId Guid

The unique ID associated with the observer to unsubscribe.

Returns

Task

A task representing the asynchronous operation.