Search code examples
silverlightxamlitemssource

How to set an ItemsSouce purely from XAMl without data binding?


I know how to data bind. But i know ive done this before where i define an array of strings or ints within Xaml. Note that im referring to Silverlight xaml.

Is it something like this?

ItemsSource="10 20 30" ItemsSource="10, 20, 30" ItemsSource="{10 20 30}" ItemsSource="{{10} {20} {30}}"

Note that none of the these actually work. The first one, for instance, places each character as a separate item in the list or combobox... etc.


Solution

  • Don't use ItemsSource. ItemsSource is specifically for binding to a collection. Controls that have an ItemsSource property typically have an Items property. Try setting it like this

    <Control>
        <Control.Items>
            10
            20
            30
        </Control.Items>
    </Control>
    

    Note that each item is on it's own line. Also, I can't tell you the syntax off of the top of my head, but I would try to create the collection as a Resource rather than declaring it in the control. This will make it easier to reuse.