简体   繁体   中英

Loading a Null String and Silverlight 4

I maintain a Silverlight 4 application. While I was out of the office, the database structure was changed and a table was dropped and its fields combined into another existing table. Now, I'm receiving the following error after I create a new item and proceed to its "summary" screen:

“Value cannot be null. Parameter name: Text At System.Windows.Controls.TextBox.set_Text(String value)”

This only happens with newly created entries, not older entries where the information on the next screen is complete (data was converted from an Excel spreadsheet and loaded into the database). So, I've narrowed it down this: the child window that is used to create a new record doesn't have all the fields that were added to the table because some of the information isn't available when the record is created. A Google search turned up that null strings can't be passed in Silverlight.

The Summary screen is loaded via ddsSummaryLoadedData domain service. If I don't include the “new” fields, then the values aren't loaded for existing entries, but new entries don't cause an error. If I do include them, older entries load correctly but new ones give the above error.

Is there a workaround to create the empty fields until they're needed, but still load data if it exists (for older entries)? Or does the child window need to be redesigned? I'm new to Silverlight and still have so much to learn!

看起来您不是在使用绑定来呈现视图,否则将妥善处理null值,因此,如果您在代码中手动设置Text属性,请使用级联运算符来验证您是否未提交null值。

myTextBox.Text = myModelValue.FirstName ?? string.Empty;

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM