views:

376

answers:

2

Set ItemsSource of a ComboBox to an Array of Integers?

A: 

Yes:

<Window x:Class="IntArrayItemsSource.Window1"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="Window1" Height="300" Width="300">
<Grid>
    <ComboBox ItemsSource="{Binding}"/>
</Grid>
</Window>


namespace IntArrayItemsSource {
/// <summary>
/// Interaction logic for Window1.xaml
/// </summary>
public partial class Window1: Window {
    public Window1() {
        InitializeComponent();
        this.DataContext = new int[] { 1, 2, 3, 4, 5, 6, 7 };
    }
}
}
Stanislav Kniazev
+2  A: 
<Window
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:sys="clr-namespace:System;assembly=mscorlib">
    <Window.Resources>
        <x:Array x:Key="Integers" Type="{x:Type sys:Int32}">
            <sys:Int32>0</sys:Int32>
            <sys:Int32>1</sys:Int32>
            <sys:Int32>2</sys:Int32>
        </x:Array>
    </Window.Resources>
    <ComboBox ItemsSource="{Binding Source={StaticResource Integers}}" />
</Window>
Shimmy