I have a class containing multiple ObservableCollection lists. When I change the contents of a list I would like the associated dropdown to repopulate its list with new values. However, when I attempt to repopulate the list, the dropdown remains unchanged from its initial values.
@using System.Collections.ObjectModel;
<SfDropDownList TValue="int"
TItem="Quantity"
<DropDownListTemplates TItem="Quantity">
<ItemTemplate>
<span><span>@((context as Quantity).NumericValue)</span> <span>@((context as Quantity).Symbol)</span></span>
</ItemTemplate>
</DropDownListTemplates>
<DropDownListFieldSettings Text="Symbol" Value="UnitValue"></DropDownListFieldSettings>
<DropDownListEvents TValue="string" ValueChange="OnPreferredUnitChange"></DropDownListEvents>
</SfDropDownList>
<p>Current value: @currentValue</p>
<button class="btn btn-primary" @onclick="IncrementCount">Increment</button>
@code {
int currentValue = 12;
public QuantityLists Lists = new QuantityLists();
protected override void OnInitialized()
{
// Build lists
Lists.AQuantityList.Add(new Quantity { NumericValue = currentValue.ToString(), UnitValue = 0, Symbol = "%P" });
Lists.AQuantityList.Add(new Quantity { NumericValue = "1.000", UnitValue = 1, Symbol = "SG" });
}
void IncrementCount()
{
currentValue++;
Lists.AQuantityList.Clear();
Lists.AQuantityList.Add(new Quantity() { NumericValue = currentValue.ToString(), UnitValue = 0, Symbol = "%P" });
Lists.AQuantityList.Add(new Quantity() { NumericValue = "2.000", UnitValue = 1, Symbol = "SG" });
}
void OnPreferredUnitChange(Syncfusion.Blazor.DropDowns.ChangeEventArgs<string> args)
{
//handle input [UnitValue]
}
public class QuantityLists
{
public ObservableCollection<Quantity> AQuantityList { get; set; }
// More lists...
public QuantityLists()
{
AQuantityList = new ObservableCollection<Quantity>();
}
}
public class Quantity
{
public string NumericValue { get; set; }
public int UnitValue { get; set; }
public string Symbol { get; set; }
}
}