I am developing wpf application, in which i have listview control. I am very new to wpf. But managed to add some styles and display horizontal gridlines inside Listview as below,
<DataTemplate x:Key="IDBorderedCellTemplate">
<Border BorderBrush="Black" Margin="0,5,0,1"
BorderThickness="0,0,0,1" >
<TextBlock Foreground="MediumBlue" FontFamily="Calibri" Margin="3,0,0,2" Text=""
/>
</Border>
</DataTemplate>
<ListView.View>
<GridView ColumnHeaderContainerStyle="{StaticResource myHeaderStyle}">
<!-- Product ID -->
<GridViewColumn
CellTemplate="{StaticResource IDBorderedCellTemplate}">
Now my problem is i am uable to display items in listview when window is loaded, which is displaying only gridlines. As my requirement is i have a browse button which i browse files, these browsed files must be displayed in listview.
As in load event i am adding following lines of code,
try
{
listviewitem = new ListViewItem();
//displays only the filename in the listview
listviewitem.Content = System.IO.Path.GetFileName(_name);
_listFiles.Items.Add(listviewitem);
}
catch (Exception)
{
}
This data is not displaying in listview after adding the gridview settings in xaml. Now its displays only gridlines.
Any suggesions/help is appreciable.
Regards
Ravi
Choose the ItemsSource of listview as ObservableCollection or BindingList
for dynamic/frequently changing data instead of using listviewItem.
XAML
C#
Can add items to ObservableCollection anywhere like browse button click or load.