Filed under: General — Oliver Sturm @ 9:20 pm - 1 year, 8 months ago
In certain contexts I have always found it useful to bind to a sequence of numbers, or sometimes even just a dummy collection with a certain number of elements. It’s like a for-loop, just for data binding. I’ve found three good ways of doing that in XAML, as the following two source code snippets show:
All these approaches come with their own advantages and disadvantages. The x:Array block can be defined completely in XAML and is obviously not restricted to sequential values. Then again, for a simple sequence, there’s a lot of typing and/or copying/pasting to be done and the result is extremely verbose. The ObjectDataProvider with the dynamically created array is an interesting approach, but the array is not actually initialized with values (so it contains a bunch of zeros) and the XAML code is also quite verbose. Finally the IntSequence looks great in XAML, but it requires a helper class, however simple. Well, there’s something for everyone here…