<ListView Name="list"
Grid.Row="1"
ItemsSource={Binding Path=Files}
>
<ListView.View>
<GridView>
<GridViewColumn Header="Name">
<GridViewColumn.CellTemplate>
<DataTemplate>
<Button>
<TextBlock Text="{BindingPath=Name}"/>
</Button>
</DataTemplate>
</GridViewColumn.CellTemplate>
</GridViewColumn>
<GridViewColumn Header="Size">
<GridViewColumn.CellTemplate>
<DataTemplate>
<Button>
<TextBlock Text="{BindingPath=Size}"/>
</Button>
</DataTemplate>
</GridViewColumn.CellTemplate>
</GridViewColumn>
<GridViewColumn Header="Path">
<GridViewColumn.CellTemplate>
<DataTemplate>
<Button>
<TextBlock Text="{BindingPath=Path}"/>
</Button>
</DataTemplate>
</GridViewColumn.CellTemplate>
</GridViewColumn>
</GridView>
</ListView.View>
</ListView>
Моя ваша ViewModel будет
public class FileListViewModel : INotifyPropertyChanged
{
/// <summary>
///
/// </summary>
public ObservableCollection<Fileinfo> Files{ get; set; }
private Fileinfo selectedFile;
public Fileinfo SelectedFile
{
get { return selectedFile; }
set
{
selectedFile= value;
InvokePropertyChanged(new PropertyChangedEventArgs("SelectedFile"));
}
}
public PersonListViewModel()
{
//Loading List
Files= new ObservableCollection<Fileinfo>()
{ //This is temp list you modify accordinh to you logic
new FileInfo{Name = "File32"},
new FileInfo{Name = "File33"},
new FileInfo{Name = "File373"},
new FileInfo{Name = "File393"},
new FileInfo{Name = "File345"},
new FileInfo{Name = "File375"},
new FileInfo{Name = "File395"},
new FileInfo{Name = "File387"},
new FileInfo{Name = "File387"}
};
}
#region Implementation of INotifyPropertyChanged
/// <summary>
///
/// </summary>
public event PropertyChangedEventHandler PropertyChanged;
/// <summary>
///
/// </summary>
/// <param name="e"></param>
public void InvokePropertyChanged(PropertyChangedEventArgs e)
{
PropertyChangedEventHandler handler = PropertyChanged;
if (handler != null)
handler(this, e);
}
#endregion
}
Ваша модель должна быть похожа на
public class FileinFo: INotifyPropertyChanged
{
private string size;
public event PropertyChangedEventHandler PropertyChanged;
private string name;
private bool isSelected;
public string Size
{
get { return size; }
set
{
size= value;
InvokePropertyChanged(new PropertyChangedEventArgs("size"));
}
}
public string Name
{
get { return name; }
set
{
name = value;
InvokePropertyChanged(new PropertyChangedEventArgs("Name"));
}
}
public bool IsSelected
{
get { return isSelected; }
set
{
isSelected = value;
InvokePropertyChanged(new PropertyChangedEventArgs("IsSelected"));
}
}
public void InvokePropertyChanged(PropertyChangedEventArgs e)
{
PropertyChangedEventHandler handler = PropertyChanged;
if (handler != null) handler(this, e);
}
}
Вам необходимо установить текст данных вашего вида View для ViewModel
так скажем, ваше представление называется FileListView.xaml
Затем в коде конструктора вы можете написать
this.DataContext= new FileListViewModel();