Skip to main content

Microsoft Silverlight

Unanswered Question AutoCompleteBox: NullReferenceException in PopulateCompleteRSS Feed

(0)

kobruleht
kobruleht

Member

Member

161 points

579 Posts

AutoCompleteBox: NullReferenceException in PopulateComplete

If LostFocus sets binding property to null
NullReferenceException occurs in PopulateComplete.
How to fix ?

Andrus.

<toolkit:AutoCompleteBox
Text="{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
jwilcox

Participant

Participant

1082 points

187 Posts

Microsoft

Re: AutoCompleteBox: NullReferenceException in PopulateComplete

Hi,

This is related to your custom web client and/or WCF service. Can you provide more details?

Jeff Wilcox [MSFT]
Silverlight
http://www.jeff.wilcox.name/blog/

This posting is provided "AS IS" with no warranties, and confers no rights.

kobruleht
kobruleht

Member

Member

161 points

579 Posts

Re: AutoCompleteBox: NullReferenceException in PopulateComplete

How to provide details ?

This forum does not allow to attach files to messages.

jwilcox
jwilcox

Participant

Participant

1082 points

187 Posts

Microsoft

Re: AutoCompleteBox: NullReferenceException in PopulateComplete

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?

Jeff Wilcox [MSFT]
Silverlight
http://www.jeff.wilcox.name/blog/

This posting is provided "AS IS" with no warranties, and confers no rights.

kobruleht
kobruleht

Member

Member

161 points

579 Posts

Re: AutoCompleteBox: NullReferenceException in PopulateComplete

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.

Andrus.

  • Unanswered Question
  • Answered Question
  • Announcement
Microsoft Communities