Skip to main content
Home Forums Silverlight Programming Silverlight Controls and Silverlight Toolkit AutoCompleteBox: NullReferenceException in PopulateComplete
4 replies. Latest Post by kobruleht on April 2, 2009.
(0)
kobruleht
Member
161 points
579 Posts
03-30-2009 6:46 AM |
If LostFocus sets binding property to nullNullReferenceException occurs in PopulateComplete. How to fix ?
Andrus.
<toolkit:AutoCompleteBoxText="{Binding Value,Mode=TwoWay}"LostFocus="AutoCompleteBox_LostFocus"Populating="AutoCompleteBox_Populating"Tag="{Binding}"/>
class FormField { public string Value;}
void AutoCompleteBox_LostFocus(object sender, RoutedEventArgs e){ AutoCompleteBox ac = (AutoCompleteBox)sender; var formField = (FormField)ac.Tag; formField.Value = null;}
void AutoCompleteBox_Populating(object sender, PopulatingEventArgs e) {var box=(AutoCompleteBox)sender;proxy.GetPickListCompleted += (s, args) => { box.ItemsSource = args.Result; // NRE occurs here: box.PopulateComplete();};}
System.NullReferenceException was unhandled by user code Message="Object reference not set to an instance of an object." StackTrace: at System.Windows.Controls.AutoCompleteBox.UpdateTextCompletion(Boolean userInitiated) at System.Windows.Controls.AutoCompleteBox.PopulateComplete() at AutoForm.PageViewModel.<>c__DisplayClass5.<Populate>b__4(Object s, GetPickListCompletedEventArgs args) at AWSilverlightLOB.StockServiceReference.StockServiceSoapClient.OnGetPickListCompleted(Object state)
jwilcox
Participant
1082 points
187 Posts
03-31-2009 8:23 PM |
Hi,
This is related to your custom web client and/or WCF service. Can you provide more details?
04-01-2009 10:29 AM |
How to provide details ?
This forum does not allow to attach files to messages.
04-01-2009 12:07 PM |
Binding to the Text property may not be the best way to go here, since that could set Text to null. How about using the ValueMemberBinding and/or SelectedItem properties instead?
04-02-2009 1:05 PM |
I replaced
Text="{Binding Value,Mode=TwoWay}"
with
ValueMemberBinding="{Binding Value,Mode=TwoWay}"
After that AutoCompleteBox does not show any data after selection.
Toolkit doc contains only one sentence about ValueMemberBinding:
Gets or sets the Binding object used for object to string conversions.
Google search for "ValeMemberbinding Silverlight" does not return any documentation.
How to use ValueMemberBinding ?
I need to select customer name but store customer id to bound property.
My picliks structure is
class Customer { public string Value, Name;
override public string ToString() { return Name; }
}
SelectedItem returns object, not customer Id. so it seems that binding to SelectedItem cannot used.