I am learning Blazor. I have no experience with component-based programming.
I have two components: a DateRangePicker
and a RadzenCheckBox
.
<RadzenFieldset Text="Test Component">
<DateRangePicker @ref="calendar" />
<div>
<Radzen.Blazor.RadzenCheckBox TValue="bool" Change="@((args) => txtBoxChange(args))" />
<RadzenLabel Text="Check" />
</div>
</RadzenFieldset>
Now, the requirement is simple. If the checkbox is clicked, show two calendars and show one calendar if it's unchecked.
I wrote the following code:
@code{
DateRangePicker calendar;
public void txtBoxChange(bool args)
{
if (args == true) //shows one calendar when checked
calendar.ShowOnlyOneCalendar = true;
else //shows two calendars when unchecked
calendar.ShowOnlyOneCalendar = false;
}
}
This works fine.
But I get a warning:
Component parameter 'ShowOnlyOneCalendar' should not be set outside of its component.
I have read some blogs about this warning, which suggest making parent and child component relationship for communication between components. But these are not parent and child.
What am I doing wrong? What is the best way to achieve such a requirement and not have this warning?
@code { ... }
block into separate code-behind files. Makes it much cleaner. – Altdorf