Я получаю очень странную ошибку на одной из моих страниц Silverlight 4.0. У меня есть форма с кнопкой «Сохранить», которая по умолчанию отключена. Эта форма заполняется группой заданных пользователем значений по умолчанию, которые исходят от асинхронного вызова сервера (MyFacade.getFormDefaults
ниже). Когда пользователь меняет одно из полей (после его заполнения), я хочу, чтобы кнопка «Сохранить» стала активной.
Я думаю, что у меня правильная логика, но я получаю очень странную ошибку, о которой не могу найти много полезной информации. Ошибка: System.InvalidOperationException: The initialization of an object or value resulted in an object or value being accessed recursively before it was fully initialized.
Ниже приведена очень упрощенная версия того, что у меня есть ...
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 <- true
внутри this.userModifiedForm
, я получу ту же ошибку. Любые идеи очень приветствуются. Спасибо.