C# 从代码隐藏填充ComboBox以显示在MyComboBox中
我在Silverlight xaml中有以下内容:C# 从代码隐藏填充ComboBox以显示在MyComboBox中,c#,silverlight,C#,Silverlight,我在Silverlight xaml中有以下内容: <UserControl........ <ScrollViewer Grid.Row="2"> <ListBox x:Name="lbList"> <ListBox.ItemTemplate> <DataTemplate> <Grid
<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>
在代码隐藏中:
static Dictionary<string, string> dictDocTypes
我用一些数据填充它。
如何在MyComboBox中显示数据?方式1
将加载的事件放在您的组合上。在该类型中,将发送者转换为组合框,并在其中填充数据
方式2纯MVVM
将命令附加到事件。在其中传递自我组合。在VM命令中,键入要组合并填充的参数对象。您有加载事件的示例吗?我在代码背后看不到MyComboBox。也许是因为它在一个列表框里?谢谢当combo加载时,其加载的事件将被触发。在事件参数中,发送方将作为对象装箱。解开它,你会得到combo。然后填上。读迈克尔。拉特萨回答这个问题