views:

206

answers:

1

I am trying to display a simple text block that shows the value of AvailableFreeSpace from IsolatedStorage.

That is: System.IO.IsolatedStorage.IsolatedStorageFile.GetUserStoreForApplication().AvailableFreeSpace

It needs to dynamically update as the available storage changes.

I know this is probably basic but I can't figure out how to bind to this variable. Any hints?

+1  A: 

When you bind a property on a plain old CLR object, like IsolatedStorageFile.AvailableFreeSpace, to a UI property like TextBlock.Text you actually need to do a little extra work to make sure that changes in the CLR property are propagated to the UI. In SL, that means the CLR object (IsolatedStorageFile in this case) needs to implement INotifyPropertyChanged. The implementation is very simple, just add an event to your object called PropertyChanged; then fire that event every time something interesting changes which would be AvailableFreeSpace in your case. Since IsolatedStorageFile doesn't implement INotifyPropertyChanged you won't get updates when the AvailableFreeSpace changes. You'll need to create your own class that implements this interface, then use some mechanism like timer based polling to check IsolatedStorageFile.AvailableFreeSpace on a regular basis and reflect changes in your own AvailableFreeSpace property. Personally I would run all write calls to isolated storage through a custom class that would check the free space after the write operation and report those changes to the class you created with a custom AvailableFreeSpace property, making sure to fire the PropertyChanged event when this happens instead of using a timer to check periodically.

James Cadd
Thanks JC. What you suggest makes sense. I was hoping it would be simpler...