0

I have following in Silverlight xaml:

<UserControl........
<ScrollViewer Grid.Row="2">
        <ListBox x:Name="lbList">
            <ListBox.ItemTemplate>
                <DataTemplate>
                    <Grid HorizontalAlignment="Stretch" >
                        <Grid.ColumnDefinitions>
                            <ColumnDefinition Width="auto"/>
                            <ColumnDefinition Width="auto"/>
                        </Grid.ColumnDefinitions>
                        <Image Source="images/Bild1.png" Grid.Column="0"/>
                        <ComboBox Name="MyComboBox" Grid.Column="1"></ComboBox>
                    </Grid>
                </DataTemplate>
            </ListBox.ItemTemplate>
        </ListBox>
    </ScrollViewer>
    .............
 </UserControl>

And in code behind:

  static Dictionary<string, string> dictDocTypes

which I populate with some Data. How to show that Data inside the MyComboBox?

Jason Aller
  • 3,541
  • 28
  • 38
  • 38
user576914
  • 199
  • 1
  • 8
  • 22

1 Answers1

0

Way 1 Put loaded event on your combo. In that typecast sender to ComboBox and populate your data in it.

Way 2 (Pure MVVM)
Attach command to event. Read here. Pass self (Combo) in it. In VM command, typecast parameter object to Combo and populate it.

Community
  • 1
  • 1
Nikhil Agrawal
  • 47,018
  • 22
  • 121
  • 208
  • Do you have any example with the loaded event? I dont see MyComboBox in code behind. maybe because is inside a ListBox? Thank you – user576914 Jun 26 '14 at 08:18
  • When combo is loaded its loaded event will be fired. In the event parameters, sender will be ComboBox boxed as Object. Unbox it and you will get combo. Then fill it. – Nikhil Agrawal Jun 26 '14 at 08:20
  • Read Michael.Laterza answer in this http://social.msdn.microsoft.com/Forums/vstudio/en-US/243f5e93-9ebc-403e-be83-a33f4245b66c/wpf-combobox-loaded-event-handling-globally?forum=wpf – Nikhil Agrawal Jun 26 '14 at 08:22