This is the first time I have used Radzen Blazor components and am already having problems creating a simple DropDown.
My razor page:
@page "/counter"
<h1>Counter</h1>
<p>Current count: @currentCount</p>
<button class="btn btn-primary" @onclick="IncrementCount">Click me</button>
<div>
<RadzenDropDown
AllowClear="true"
AllowFiltering="true"
FilterCaseSensitivity="FilterCaseSensitivity.CaseInsensitive"
Data=@MyFruits
@bind-Value=@Selected.Name
TextProperty="Name"
ValueProperty="Name"
Style="width:400px"
Change=@(args => ChangeBound(args, "DropDown with bound Value")) />
</div>
My code-behind:
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Linq;
using System.Threading.Tasks;
namespace RadzenTest.Pages
{
public partial class Counter
{
private int currentCount = 0;
private ObservableCollection<Fruit> MyFruits { get; set; }
private Fruit Selected { get; set; }
private void IncrementCount()
{
currentCount++;
}
protected override void OnInitialized()
{
base.OnInitialized();
MyFruits = new ObservableCollection<Fruit>();
MyFruits.Add( new Fruit() { Id = 1, Name = "Apple", Colour = "Green" } );
MyFruits.Add( new Fruit() { Id = 2, Name = "Apple", Colour = "Red" } );
MyFruits.Add( new Fruit() { Id = 3, Name = "Lemon", Colour = "Yellow" } );
MyFruits.Add( new Fruit() { Id = 4, Name = "Lime", Colour = "Green" } );
Selected = MyFruits.FirstOrDefault( x => x.Name.Equals( "Lemon" ) );
}
void ChangeBound( object value, string name )
{
Console.WriteLine( $"{name} value changed to {Selected.Name}" );
}
}
public sealed class Fruit
{
public int Id { get; set; }
public string Name { get; set; }
public string Colour { get; set; }
}
}
See the attached screenshot which shows that the dropdown appears as a bulleted list at the bottom of the page, now a dropdown list under the DropDown control.
What am I missing ?
Andy