0

I recently started tampering with Windows store apps. I'm having trouble referencing my objects properly. At first, when trying to automatically update a ScrollViewer object when a ComboBox object changed, I couldn't get the value of the changed index.

Using menuDay.SelectedIndex within my menuDay_SelectionChanged event caused a System.NullReferenceException. I fixed that by referencing my menuDay object as such:

((ComboBox)sender).SelectedIndex

Now, within the same menuDay_SelectionChanged event, I'm getting the same error when I try accessing the content of my ScrollViewer, outSetList.

I'm trying to set my ScrollViewer's content to a list of exercise activities. Too much to post. But I concatenate them using a single string.

string += "this stuff\n" repeat.

And then I try to set it into the ScrollViewer

outSetList.content = string

I get the same System.NullReferenceException error. It tells me that the object reference is not set to an instance of an object.

I'm pretty familiar with C#, objects, instances but nothing I've tried seems to have worked. I tried casting it, creating a variable using it as a type(outSetlist setlist = new outSetList) among other things.

I'm sure it's a fairly simple answer but I can't find one anywhere.

  • possible duplicate of [What is a NullReferenceException and how do I fix it?](http://stackoverflow.com/questions/4660142/what-is-a-nullreferenceexception-and-how-do-i-fix-it) – crthompson Oct 10 '14 at 03:10
  • I think the xaml object are not initialized properly. Can you verify the InitializeComponent() routine is there in your constructor. – jadavparesh06 Oct 10 '14 at 03:18
  • If you're working with XAML based technologies, you need to properly understand the MVVM pattern, which is the preferred way to interact with XAML UIs. Otherwise you will suffer a lot fighting the framework and trying to procedurally manipulate the Visual Tree which is a complex structure. – Federico Berasategui Oct 10 '14 at 03:18
  • Basically, you don't "automatically update a ScrollViewer", nor "get the value of the changed index", or anything like that. Instead, you use proper DataBinding and create a simple class which contains the data you want to show and the logic needed to operate against the data, which is completely decoupled from the UI. – Federico Berasategui Oct 10 '14 at 03:21

0 Answers0