-
Notifications
You must be signed in to change notification settings - Fork 7
Open
Description
I've created multiple sets of widgets so I could switch between them using a button.
Index.razor
@page "/"
@using BlazorGridStack.Models
@using System.Diagnostics.CodeAnalysis;
@foreach (var info in infos)
{
<div>@info</div>
}
<button @onclick=OnClick>Change Widgets</button>
<BlazorGridStackBody @ref=grid GridStackOptions=options OnChange=OnChange>
@foreach (var item in items)
{
<BlazorGridStackWidget WidgetOptions=item>
<MyComponent Name=@item.Id.ToString() />
</BlazorGridStackWidget>
}
</BlazorGridStackBody>
@code {
bool flag;
[AllowNull]
BlazorGridStackBody grid;
BlazorGridStackBodyOptions options = new()
{
Row = 10
};
IEnumerable<string> infos = Enumerable.Empty<string>();
IEnumerable<BlazorGridStackWidgetOptions> items => flag ? items1 : items2;
IEnumerable<BlazorGridStackWidgetOptions> items1 = new[] {
new BlazorGridStackWidgetOptions {Id = "A", W = 2, H = 2},
new BlazorGridStackWidgetOptions {Id = "B", W = 3, H = 3, X = 3, Y = 0},
new BlazorGridStackWidgetOptions {Id = "C", W = 3, H = 3, X = 3, Y = 3},
};
IEnumerable<BlazorGridStackWidgetOptions> items2 = new[] {
new BlazorGridStackWidgetOptions {Id = "1", W = 2, H = 2},
new BlazorGridStackWidgetOptions {Id = "2", W = 2, H = 2, X = 3, Y = 3},
};
void OnClick()
{
flag = !flag;
}
private void OnChange(BlazorGridStackWidgetListEventArgs e)
{
infos = e.Items.Select(x => $"Id: {x.Id ?? "NULL"}, Content: {x.Content.Substring(0, 20)}...");
}
}
MyComponent.razor
<h3>@Name.ToUpper()</h3>
@code {
[Parameter]
public string Name { get; set; }
}
As the items get switched, not all the corresponding widgets get created by the body. Actually the 3rd widget "C", not getting detected by the body making it not draggable. how to make it to work? Thanks.
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels