Derik Whittaker

Syndication

News


Runtime Exception for PageIndex of a DataPager

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

image

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.

Original XAML

image

Correct XAML

image

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,


Posted 11-29-2011 9:25 AM by Derik Whittaker
Filed under: ,

[Advertisement]

Comments

viagra wrote re: Runtime Exception for PageIndex of a DataPager
on 11-30-2011 3:18 PM

hzmsqi  <a href="http://jrsdjj.com/ ">quqozx</a>

viagra wrote re: Runtime Exception for PageIndex of a DataPager
on 11-30-2011 11:25 PM

gwgimoxk  [url=http://maaura.com/]rdqvfhy[/url]

Ganesh wrote re: Runtime Exception for PageIndex of a DataPager
on 12-02-2011 11:16 AM

I have had similar experience with combobox where selectitem was being set before itemssource, because of which it never set the selectitem on load, when there was one. Reversing the order worked!

Pankaj wrote re: Runtime Exception for PageIndex of a DataPager
on 01-23-2012 4:31 AM

www

Pankaj wrote re: Runtime Exception for PageIndex of a DataPager
on 01-23-2012 4:40 AM

I also had the same issue with my datapager. I did what u hv said but still the same problem is occuring. Is there any other solution. If i am setting my PageIndex property to -1, my data in the listview is flickering.

About The CodeBetter.Com Blog Network
CodeBetter.Com FAQ

Our Mission

Advertisers should contact Brendan

Subscribe
Google Reader or Homepage

del.icio.us CodeBetter.com Latest Items
Add to My Yahoo!
Subscribe with Bloglines
Subscribe in NewsGator Online
Subscribe with myFeedster
Add to My AOL
Furl CodeBetter.com Latest Items
Subscribe in Rojo

Member Projects
DimeCasts.Net - Derik Whittaker

Friends of Devlicio.us
Red-Gate Tools For SQL and .NET

NDepend

SlickEdit
 
SmartInspect .NET Logging
NGEDIT: ViEmu and Codekana
LiteAccounting.Com
DevExpress
Fixx
NHibernate Profiler
Unfuddle
Balsamiq Mockups
Scrumy
JetBrains - ReSharper
Umbraco
NServiceBus
RavenDb
Web Sequence Diagrams
Ducksboard<-- NEW Friend!

 



Site Copyright © 2007 CodeBetter.Com
Content Copyright Individual Bloggers

 

Community Server (Commercial Edition)