@using Accordion.Data
@using Syncfusion.Blazor.Navigations
@implements IDisposable
@inject IJSRuntime jsRuntime
<SfAccordion @ref="AccordionRef">
<AccordionItems>
<AccordionItem @bind-Expanded="IsExpanded" Header="Margeret Peacock" Content="Margeret Peacock was born on Saturday , 01 December 1990. Now lives at Coventry House Miner Rd., London,UK. Margeret Peacock holds a position of Sales Coordinator in our WA department, (Seattle USA). Joined our company on Saturday , 01 May 2010"></AccordionItem>
<AccordionItem @bind-Expanded="IsExpanded" Header="Laura Callahan" Content="Laura Callahan was born on Tuesday , 06 November 1990. Now lives at Edgeham Hollow Winchester Way, London,UK. Laura Callahan holds a position of Sales Coordinator in our WA department, (Seattle USA). Joined our company on Saturday , 01 May 2010"></AccordionItem>
<AccordionItem @bind-Expanded="IsExpanded" Header="Albert Dodsworth" Content="Albert Dodsworth was born on Thursday , 19 October 1989. Now lives at 4726 - 11th Ave. N.E., Seattle,USA.Albert Dodsworth holds a position of Sales Representative in our WA department, (Seattle USA). Joined our company on Friday , 01 May 2009"></AccordionItem>
</AccordionItems>
</SfAccordion>
@code{
SfAccordion AccordionRef;
bool IsExpanded;
protected override void OnInitialized()
{
BrowserResizeService.WindowResize += ResizeWindow;
}
protected override async Task OnAfterRenderAsync(bool firstRender)
{
if(firstRender)
{
int windowHeight = await jsRuntime.InvokeAsync<int>("getInnerHeight");
if (windowHeight < 400)
{
IsExpanded = false;
}
else
{
IsExpanded = true;
StateHasChanged();
}
}
}
public void Dispose()
{
BrowserResizeService.WindowResize -= ResizeWindow;
}
protected async Task ResizeWindow()
{
if (BrowserResizeService.WindowHeight < 400)
{
IsExpanded = false;
StateHasChanged();
}
else
{
IsExpanded = true;
StateHasChanged();
}
}
} |
function getInnerHeight() {
return window.innerHeight;
}
function getInnerWidth() {
return window.innerWidth;
}
function raiseResizeEvent() {
var namespace = 'Accordion'; // the namespace of the app, you will have to change this for your app
var method = 'RaiseWindowResizeEvent'; //the name of the method in our "service"
DotNet.invokeMethodAsync(namespace, method, Math.floor(window.innerWidth), Math.floor(window.innerHeight));
}
var timeout = false;
window.addEventListener("resize", function () {
if (timeout !== false)
clearTimeout(timeout);
timeout = setTimeout(raiseResizeEvent, 200);
}); |
public class BrowserResizeService
{
public static event Func<Task> WindowResize;
public static int? WindowWidth { get; private set; }
public static int? WindowHeight { get; private set; }
[JSInvokable]
public static async Task RaiseWindowResizeEvent(int width, int height)
{
WindowWidth = width;
WindowHeight = height;
try
{
await WindowResize?.Invoke();
}
catch { }
}
} |