Passing data to the listbox in usercontrol
Hai am creating a usercontol with two textblock and one listbox. i can able to pass dat开发者_如何学Ca to textblock in my usercontorl. but i cannot pass the data to my listbox in usercontrol. how to pass my data in the usercontrol
public partial class UserControl1 : UserControl
{
public UserControl1()
{
InitializeComponent();
}
public string TeamName
{
get { return textBlock1.Text; }
set { textBlock1.Text = value; }
}
public ObservableCollection<CssRpt> CssDataList
{
get { return listBox1.ItemsSource; }
set { listBox1.ItemsSource = value; }
}
}
You can check how to add data to a list box on this msdn tutorial.
Did you try assigning into .DataContext
? See this answer.
Try this
YourListBox.DataSource = CssDataList
YourListBox.DisplayMember = "What u want to display"
精彩评论