I've got a UserControl with a ObservableCollection member.
In the UserControl i have a ListBox and i want the ListBox ItemsSource to be the the UserControls ObservableCollection.
UserControl:
public partial class Timeline : UserControl
{
public ObservableCollection<TwitterStatus> Tweets = new ObservableCollection<TwitterStatus>();
public string TwitterTimeline { get; set; }
public string Title { get; set; }
public Timeline()
{
InitializeComponent();
Loaded += new RoutedEventHandler(UserControl_Loaded);
}
public void RefreshTimeline(TwitterResponse<TwitterStatusCollection> twitterResponse)
{
Tweets.Clear();
foreach (TwitterStatus t in twitterResponse.ResponseObject)
{
Tweets.Add(t);
}
this.ApplyDataBinding();
}
private void ApplyDataBinding()
{
TweetList.ItemsSource = null;
TweetList.ItemsSource = Tweets;
}
private void UserControl_Loaded(object sender, RoutedEventArgs e)
{
this.ApplyDataBinding();
}
}
I think I've tried every possible way, i just cant get it to work. The ListBox is just empty. Am i doing something wrong?