如何在silverlight中将dataContext的值赋给ListBox控件?

时间:2010-02-24 14:56:57

标签: silverlight

您好我的用户控件中有contentControl。我正在为这个由TextBlock和ListBox组成的contentControl应用样式。我将textBlock的文本绑定到CategoryName(来自控件的Tag)。我想将类别的子项绑定到listBox。我已将ContentControl的dataContext属性设置为子项[]。现在,如何将这些子项绑定到资源中的列表框。

                        

在用户控件的加载事件中 Panel pnl =发送者为Panel; Category category = panel.Tag as Category; Items [] items = GetChildItemsByCategoryId(category.CategoryID); mainContent.DataContext = items;

1 个答案:

答案 0 :(得分:0)

如果控件位于mainContent的可视树中,只需在代码或XAML中设置

的ItemsSource = {结合}

相关问题