Here is the code for which the data binding is not working. XAML
<ListBox x:Name="RecentBox" SelectionChanged="RecentBox_SelectionChanged" ItemsSource="{Binding}" >
<ListBox.ItemTemplate>
<DataTemplate>
<Border BorderBrush="Red" BorderThickness="1" Background="Blue">
<TextBlock Text="{Binding RecentItemList}"/>
</Border>
</DataTemplate>
</ListBox.ItemTemplate>
</ListBox>
Now the CS code
public ObservableCollection<string> RecentItemsList { get { return new ObservableCollection<string>(((MainWindow)Application.Current.MainWindow).cacheFileList); } }
public RecentItems()
{
InitializeComponent();
RecentBox.ItemsSource = RecentItemsList;
}
Now how to bind the string to the Textblock element?