Today I was building a UI in Silverlight which needed a Data Grid and a Data Pager. When I setup my pager I had it bound to the various properties that I cared about (Source, PageIndex, PageSize, etc) via my ViewModel. However when I ran the page for the first time I received the error below
At first I was a bit stumped because why in the world would I want to set my Page Index to –1 (as an FYI my Source property is NULL when first bound because of the way we lazy fetch our data. In order to get around this I did what the error told me and set my Page Index to default to –1. This worked… kinda. See it worked the first time I loaded the screen when there was NO data loaded in memory. Every subsequent loading of the page threw another exception telling me that my default Page Index had to be >= 0.
As I sat there scratching my head it dawned on me that the issue was due to the way that the XAML engine reads/parses the elements (left to right, top to bottom). I reset my default Page Index to 0 and moved my Source property to the left of my PageIndex property and this worked. Take a look below at my XAML to see the difference.
The moral of the story is that you need to pay attention to the order (left to right/top to bottom) of your XAML properties in some places.
Till next time,
11-29-2011 9:25 AM