Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/silverlight/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Xaml Silverlight 4.0表单初始化问题_Xaml_Silverlight_F#_Silverlight 4.0 - Fatal编程技术网

Xaml Silverlight 4.0表单初始化问题

Xaml Silverlight 4.0表单初始化问题,xaml,silverlight,f#,silverlight-4.0,Xaml,Silverlight,F#,Silverlight 4.0,我在Silverlight 4.0的一个页面上遇到了一个非常奇怪的错误。我有一个表单,它有一个默认禁用的“保存”按钮。此表单由一组用户指定的默认值填充,这些默认值来自异步服务器调用(MyFacade.getFormDefaults)。当用户更改其中一个字段时(填充后),我希望启用“保存”按钮 我想我的逻辑是正确的,但是我得到了一个非常奇怪的错误,我找不到很多有用的信息。错误为:System.invalidoOperationException:对象或值的初始化导致在对象或值完全初始化之前递归访问

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

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

下面是一个非常简单的版本,我有

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
        ()
<nav:Page Name="profile" Loaded="formLoaded">
    <TextBox Name="txtEmail" TextChanged="userModifiedForm "/>
    <Button Name="btnSave" IsEnabled="False"/>
</nav:Page>
type profile()如下所示=
继承UriUserControl(“/whatever;component/profile.xaml”,“profile”)
[]
val可变isFormLoaded:bool
[]
val可变btnSave:按钮
[]
val可变TXTMail:文本框
//建造师
做
this.isFormLoaded当对象在完全初始化之前被访问时,F#运行时会生成异常——“对象或值的初始化导致对象或值在完全初始化之前被递归访问”


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

我假设其中一个XAML字段(如文本框、组合框或复选框)正在触发TextChanged或SelectionChanged事件并调用
userModifiedForm
。所以,是的,你是对的。。。但我如何防止这种情况发生?Silverlight会在表单完全构建之前触发这些事件,这很烦人。如果这就是问题所在,最简单的解决方案可能是只将
userModifiedForm
附加到构造函数末尾的
txtEmail
上,而不是附加到xaml文件中。wmeyer的建议应该有效——Silverlight为其辩护:因为它没有与F#type系统集成,我不确定它如何自动避免造成这个问题。