Ticket T1137771
Visible to All Users

How to handle Warning:BL0007 on a Component with a DxCheckBox only

created 2 years ago

After updating to net.7 we are getting Warnings for our Blazor Components.
Heres an example

Warning BL0007: Component parameter 'WebCenter.Layout.Shared.Components.InfoCheckbox.Checked' should be auto property

I know how to handle the warning when i have a method inside of the Component
you can call CheckedChanged.InvokeAsync(); inside of the method.
But in this component i have no method that is being called.

Is there a way to get around the warning? Like another way to bind to the <DxCheckBox> or something like that?

If i just convert the property Checked to an auto property the caller does not get the correct value.
any help would be great…

Razor
<div class="wrapper mb-2"> <DxCheckBox @bind-Checked="Checked" CssClass="stretch-TextBox">@Label</DxCheckBox> <button class="btn btn-secondary button-min-31 m-l-5" type="button" data-toggle="collapse" data-target="@_idd" aria-expanded="false" aria-controls="collapseExample"> <span class="fas fa-info"> </span> </button> </div> <div class="collapse" id="@_id"> <div class="card card-body"> @ChildContent </div> </div> @code { [Parameter] public string Label { get; set; } = default!; // Raises Warning BL0007 [Parameter] public bool Checked { get => _checked; set { if (_checked == value) return; _checked = value; CheckedChanged.InvokeAsync(value); } } [Parameter] public RenderFragment ChildContent { get; set; } = default!; [Parameter] public EventCallback<bool> CheckedChanged { get; set; } private bool _checked; protected override void OnInitialized() { _id = $"spinner{Guid.NewGuid():N}"; _idd = $"#{_id}"; } private string _id = default!; private string _idd = default!; }

example of a caller

Razor
<DxFormLayoutItem Caption="@Resources.App.DisplayFQDN" ColSpanMd="12" CssClass="m-b-5"> <Template> <InfoCheckbox @bind-Checked="settings.ValidateIPAddressOnPrintServerImport" Label="@Resources.App.DisplayFQDN"> @this.Raw(Resources.App.ValidateIPAddressOnPrintServerImportDescription) </InfoCheckbox> </Template> </DxFormLayoutItem>

We have the same problem with DxSpinEdit

Answers approved by DevExpress Support

created 2 years ago

Hello,

The BL0007 warning was implemented because of the following GitHub issue: Consider an analyzer to warn if a [Parameter] property isn't a simple auto property. It will be displayed if a [Parameter] property isn't just a simple { get; set; } one. So, I suppose that the cause is the following code:

Razor
[Parameter] public bool Checked { get => _checked; set { if (_checked == value) return; _checked = value; CheckedChanged.InvokeAsync(value); } }

I suppose that it's necessary to organize this property in another way and bind DxCheckBox to the internal component's property rather than to the public [Parameter] property.
Our component doesn't matter in this usage scenario; you will get the same result with any other component.

Regards,
Vova

    Comments (2)

      Doesn't feel right but this would work. Thank's for your suggestions.

      C#
      <div class="wrapper mb-2"> <DxCheckBox @bind-Checked="CheckBoxValue" CssClass="stretch-TextBox">@Label</DxCheckBox> </div> @code { private bool _checkBoxValue; [Parameter] public string Label { get; set; } = default!; [Parameter] public bool Checked { get; set; } [Parameter] public EventCallback<bool> CheckedChanged { get; set; } public bool CheckBoxValue { get => _checkBoxValue; set { _checkBoxValue = value; CheckedChanged.InvokeAsync(value); } } protected override void OnInitialized() { CheckBoxValue = Checked; }
      Vova (DevExpress Support) 2 years ago

        You are welcome.
        Your code seems to be OK. However, I would additionally set the _checkBoxValue property value in the OnInitialized event, since now it should invoke the CheckedChanged event on initialization.

        Regards,
        Vova

        Disclaimer: The information provided on DevExpress.com and affiliated web properties (including the DevExpress Support Center) is provided "as is" without warranty of any kind. Developer Express Inc disclaims all warranties, either express or implied, including the warranties of merchantability and fitness for a particular purpose. Please refer to the DevExpress.com Website Terms of Use for more information in this regard.

        Confidential Information: Developer Express Inc does not wish to receive, will not act to procure, nor will it solicit, confidential or proprietary materials and information from you through the DevExpress Support Center or its web properties. Any and all materials or information divulged during chats, email communications, online discussions, Support Center tickets, or made available to Developer Express Inc in any manner will be deemed NOT to be confidential by Developer Express Inc. Please refer to the DevExpress.com Website Terms of Use for more information in this regard.