Maui Blazor – 传递组件 @ref 时的 CS0029 错误。

huangapple go评论80阅读模式
英文:

Maui Blazor - CS0029 when passing component @ref

问题

After updating Visual Studio to version 17.6.0, the following error occurred in my MAUI project:

> Error CS0029 Cannot implicitly convert type 'Microsoft.AspNetCore.Components.ElementReference' to '<componentName>'

以下是我的代码:

@using UI.Components.Dialogs.InfoDialog
@using UI.Components.Dialogs.InputDialog
@using UI.Components.Dialogs.MessageDialog
@using UI.Components.Dialogs.SettingsDialog
@using UI.Components.Dialogs.ProcedureTypeSelectorDialog
@using UI.Services;

@inject DialogService dialogService

<InputDialog @ref="inputDialog" />
<InfoDialog @ref="infoDialog" />
<MessageDialog @ref="messageDialog" />
<SettingsDialog @ref="settingsDialog" />
<ProcedureTypeSelectorDialog @ref="procedureTypeSelectorDialog" />

@code {
    InputDialog inputDialog { set => dialogService.RegisterDialog(value); }
    InfoDialog infoDialog { set => dialogService.RegisterDialog(value); }
    MessageDialog messageDialog { set => dialogService.RegisterDialog(value); }
    SettingsDialog settingsDialog { set => dialogService.RegisterDialog(value); }
    ProcedureTypeSelectorDialog procedureTypeSelectorDialog { set => dialogService.RegisterDialog(value); }
}

我已尝试以下操作:

  1. 将所有内容转移到代码后端
  2. 删除命名空间和组件名称的重复(实际上,我将组件从它们的文件夹中提取出来)
  3. 寻找将 ElementReference 转换或从中提取我的组件的方法(未找到相关信息)
  4. 删除了 .vs、bin 和 obj 文件夹,并重新构建了项目

在更新 Visual Studio 之前(我使用的是版本 17.5),这段代码可以正常工作。更新后,尝试使用相同的代码运行时,出现了这个错误。提前感谢大家的帮助!

英文:

After updating Visual Studio to version 17.6.0, the following error occurred in my MAUI project:

> Error CS0029 Cannot implicitly convert type 'Microsoft.AspNetCore.Components.ElementReference' to '<componentName>'

Maui Blazor – 传递组件 @ref 时的 CS0029 错误。


Here is my code:

@using UI.Components.Dialogs.InfoDialog
@using UI.Components.Dialogs.InputDialog
@using UI.Components.Dialogs.MessageDialog
@using UI.Components.Dialogs.SettingsDialog
@using UI.Components.Dialogs.ProcedureTypeSelectorDialog
@using UI.Services;

@inject DialogService dialogService

<InputDialog @ref="inputDialog" />
<InfoDialog @ref="infoDialog" />
<MessageDialog @ref="messageDialog" />
<SettingsDialog @ref="settingsDialog" />
<ProcedureTypeSelectorDialog @ref="procedureTypeSelectorDialog" />

@code {
    InputDialog inputDialog { set => dialogService.RegisterDialog(value); }
    InfoDialog infoDialog { set => dialogService.RegisterDialog(value); }
    MessageDialog messageDialog { set => dialogService.RegisterDialog(value); }
    SettingsDialog settingsDialog { set => dialogService.RegisterDialog(value); }
    ProcedureTypeSelectorDialog procedureTypeSelectorDialog { set => dialogService.RegisterDialog(value); }
}

I have tried the following:

  1. Transfer everything to the codebehind
  2. Remove the duplication of the namespace and the name of the component (in fact, I pulled the components from their folders)
  3. I was looking for ways to convert ElementReference or extract my component from it (I didn't find anything like that)
  4. Deleted folders .vs, bin, obj and rebuilt the project

Before updating Visual Studio (I was working on version 17.5), this code worked fine. After the update, when trying to run with the same code, I encountered this error. Thank you all in advance for your help!

答案1

得分: 1

这可能是在新版本的Visual Studio 17.6.0上出现的问题。我建议你在GitHub上报告它作为一个新问题,并报告一个与Visual Studio产品相关的问题以获取更多信息。

英文:

This might be an issue on the new version of Visual Studio 17.6.0. I recommend you to report it as a new issue on the GitHub and report a problem with the Visual Studio product for more information.

答案2

得分: 0

"Its reported on dotnet/AspNetCore.Docs

https://github.com/dotnet/AspNetCore.Docs/issues/17416"

英文:

Its reported on dotnet/AspNetCore.Docs

https://github.com/dotnet/AspNetCore.Docs/issues/17416

huangapple
  • 本文由 发表于 2023年5月18日 01:01:50
  • 转载请务必保留本文链接:https://go.coder-hub.com/76274539.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定