0

I have an Array bound to a ComboBox.

My issue is that I can't find a way to default ComboBox element to any of the ones in the Array, i.e. it's empty when loading the User Control.

Would this be due to the way I load the array (from a dictionnary)?

XAML binding:

<WrapPanel>
    <ComboBox ItemsSource="{Binding Path=ExclusionDescriptions}" SelectedValue="{Binding Path=Description, Mode=TwoWay}" IsSynchronizedWithCurrentItem="True" SelectedIndex="0"/>
</WrapPanel>

Code:

public string[] ExclusionDescriptions 
{
    get
    {
        return GetDescriptionsAndEntityScope().Keys.ToArray(); 
    }
}

With:

    private Dictionary<string, bool> GetDescriptionsAndEntityScope()
    {
        return GetDescriptionsAndEntityScope();
    }
goul
  • 813
  • 1
  • 13
  • 32
  • How are you setting the `Description` property? Does it have a value? – lc. Mar 05 '14 at 08:17
  • Yes, there is some values. The dropdown is populated, just that the selection when loaded is on nothing (empty selection). Would like to default it to the first element for example – goul Mar 05 '14 at 08:21
  • How about this [link](http://stackoverflow.com/questions/1910896/display-a-default-value-for-a-databound-wpf-combobox) – mbm Mar 05 '14 at 08:21
  • 1
    when your viewmodel or control starts up, set the Description property to ExclusionDescriptions[0], and ensure that NotifyPropertyChanged is raised – Spook Kruger Mar 05 '14 at 08:22
  • Can we see your code for `Description`? – lc. Mar 05 '14 at 08:24
  • Try binding SelectedItem or SelectedIndex. It may work.. – Victory Jessie Mar 05 '14 at 08:29
  • Thank you all. Set this in the code as I couldn't make this working with triggers in the XAML. Not big fan though of doing so, and not sure why this doesn't work by default. SelectedExclusionDescription = CouterpartyLevelExclusionDescriptions[0];) – goul Mar 05 '14 at 09:04
  • set SelectedIndex="0" in XAML. It may work for your case – Anees Deen Mar 05 '14 at 11:19

0 Answers0