I had a similar problem with binding an array of integers coming from ViewModel to ComboBox. Here is what worked for me.
Here is XAML where we bind the property ArrayOfIntegersto a ItemsSourceComboBox
<Window x:Class="POpUpWindow.comboBox"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="comboBox" Height="300" Width="300">
<Grid>
<ComboBox x:Name="combox" IsReadOnly="True"
VerticalAlignment="Center" SelectedIndex="0"
ItemsSource="{Binding ArrayOfIntegers}">
</ComboBox>
</Grid>
</Window>
Here is the code behind and the ViewModel that has the property ArrayOfIntegers
public partial class comboBox : Window
{
private ViewModel mViewModel = new ViewModel();
public comboBox()
{
InitializeComponent();
this.DataContext = mViewModel;
}
}
public class ViewModel : ViewModelBase
{
public ViewModel()
{
ArrayOfIntegers = new int[]{4, 6, 9};
}
private int[] mArrayOfIntegers = new int[3];
public int[] ArrayOfIntegers
{
get { return mArrayOfIntegers; }
set { mArrayOfIntegers = value; }
}
}
source
share