开发者

Passing data to the listbox in usercontrol

开发者 https://www.devze.com 2023-01-01 02:02 出处:网络
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 p

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"
0

精彩评论

暂无评论...
验证码 换一张
取 消