Silverlight 4.0表单初始化问题

发布于 2024-10-20 11:33:06 字数 1982 浏览 0 评论 0原文

我在 Silverlight 4.0 页面之一上遇到一个非常奇怪的错误。我有一个带有“保存”按钮的表单,默认情况下该按钮处于禁用状态。该表单由一堆用户指定的默认值填充,这些默认值来自异步服务器调用(下面的MyFacade.getFormDefaults)。当用户更改其中一个字段(填充后)时,我希望启用“保存”按钮。

我认为我的逻辑是正确的,但我遇到了一个非常奇怪的错误,我找不到太多有用的信息。错误是:System.InvalidOperationException:对象或值的初始化导致对象或值在完全初始化之前被递归访问。

下面是我所拥有的非常简化的版本...

profile.fs:

type profile() as this =
    inherit UriUserControl("/whatever;component/profile.xaml", "profile")

    [<DefaultValue>]
    val mutable isFormLoaded : bool
    [<DefaultValue>]
    val mutable btnSave : Button
    [<DefaultValue>]
    val mutable txtEmail : TextBox

    // constructor
    do
        this.isFormLoaded <- false

        // make the "this" values point at the XAML fields
        this.btnSave <- this?btnSave
        this.txtEmail <- this?txtEmail

        // get the form defaults and send them to
        MyFacade.getFormDefaults(new Action<_>(this.populateFormDefaults))
        ()

    member this.populateFormDefaults (formDefaults : MyFormDefaultsUIVO array option) =
        // populate this.txtEmail with the default value here
        this.isFormLoaded <- true // set the form to be loaded once that's done
        ()

    // enable the "Save" button when the user modifies a form field
    member this.userModifiedForm (sender : obj) (args : EventArgs) =
        // **** EXCEPTION OCCURS ON THE LINE BELOW ****
        if this.isFormLoaded then
            this.btnSave.IsEnabled <- true
        ()

profile.xaml:

<nav:Page Name="profile" Loaded="formLoaded">
    <TextBox Name="txtEmail" TextChanged="userModifiedForm "/>
    <Button Name="btnSave" IsEnabled="False"/>
</nav:Page>

即使我摆脱了所有 isFormLoaded 逻辑,并简单地设置 this.btnSave。 IsEnabled <- truethis.userModifiedForm 内部,我得到同样的错误。任何想法将不胜感激。谢谢。

I am getting a very strange error on one of my Silverlight 4.0 pages. I have a form that has a "save" button which is disabled by default. This form gets populated by a bunch of user-specified defaults, which come from an asynchronous server call (MyFacade.getFormDefaults below). When the user changes one of the fields (after it's populated), I want the "save" button to become enabled.

I think I have the logic correct, but I'm getting a very strange error that I can't find much useful information on. The error is: System.InvalidOperationException: The initialization of an object or value resulted in an object or value being accessed recursively before it was fully initialized.

Below is a very simplified version of what I have...

profile.fs:

type profile() as this =
    inherit UriUserControl("/whatever;component/profile.xaml", "profile")

    [<DefaultValue>]
    val mutable isFormLoaded : bool
    [<DefaultValue>]
    val mutable btnSave : Button
    [<DefaultValue>]
    val mutable txtEmail : TextBox

    // constructor
    do
        this.isFormLoaded <- false

        // make the "this" values point at the XAML fields
        this.btnSave <- this?btnSave
        this.txtEmail <- this?txtEmail

        // get the form defaults and send them to
        MyFacade.getFormDefaults(new Action<_>(this.populateFormDefaults))
        ()

    member this.populateFormDefaults (formDefaults : MyFormDefaultsUIVO array option) =
        // populate this.txtEmail with the default value here
        this.isFormLoaded <- true // set the form to be loaded once that's done
        ()

    // enable the "Save" button when the user modifies a form field
    member this.userModifiedForm (sender : obj) (args : EventArgs) =
        // **** EXCEPTION OCCURS ON THE LINE BELOW ****
        if this.isFormLoaded then
            this.btnSave.IsEnabled <- true
        ()

profile.xaml:

<nav:Page Name="profile" Loaded="formLoaded">
    <TextBox Name="txtEmail" TextChanged="userModifiedForm "/>
    <Button Name="btnSave" IsEnabled="False"/>
</nav:Page>

Even if I get rid of all the isFormLoaded logic, and simply set this.btnSave.IsEnabled <- true inside of this.userModifiedForm, I get the same error. Any ideas would be greatly appreciated. Thanks.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

ゝ偶尔ゞ 2024-10-27 11:33:06

当在完全初始化之前访问对象时,F# 运行时会生成异常“对象或值的初始化导致对象或值在完全初始化之前被递归访问”。

在构造函数运行之前访问 this - 是否检查 isFormLoadedbtnSave.IsEnabled - 将导致错误。您是否已验证 userModifiedForm 仅在构造函数之后调用?

The exception - "The initialization of an object or value resulted in an object or value being accessed recursively before it was fully initialized" - is generated by the F# runtime when an object is accessed before being fully initialized.

Accessing this - whether to check isFormLoaded or btnSave.IsEnabled - before the constructor has run will cause the error. Have you verified that userModifiedForm is only called after the constructor?

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文