Binding to Indexers

A while ago I played around with DataBinding an tried to implement a Sudoku Game similar to Sudoku in the WPF tutorial https://blogs.msdn.com/coding4fun/archive/2006/11/06/999502.aspx 

One thing that is not in that game is, that some People (including me :-) ) like to enter all possible numbers in each cells of the grid and narrow it down stp by step till only one number is left in the cell.

I implemented a kind of a bit-set that can contains digits from 1 to 9. And wanted to bind it to each of the 9x9 cells of the Sudoku game in a small grid where the digits are shown or hidden accordingly.

clip_image001[4]

I exposed the individual digits through an indexer that returns a Boolean value.

I bind this bitset to a TextBlock that is either shown or hidden according to the Boolean value of the indexer

image 

This goes on for all nine elements. I had to use a converter since the Visibility is not boolean but an enumeration.

It worked great, only the digits are shown that are in the bitset.

 

But: updates to the bitset where not reflected in the UI. I knew it had something to do with INotifyPropertyChange or INotifyCollectionChanged but couldn't find anything.

Beatriz Costa https://www.beacosta.com/blog/ helped me and showed me that the Binding class is looking for "Item[]" in the argument of the PorpertyChanged Event

So with the following code did it :

image

Thanks Beatriz.

Comments

  • Anonymous
    September 28, 2007
    That is cool! :) I love seeing the great apps people come up with, when using data binding! Keep blogging! Bea