I am using a WPF application. I am new to wpf but I have experience with Windows Forms. Wpf is great I want to learn how to programme with it. My problem is: I have written a code, I can use it but its not possible for me to use the OpenFileDialog function correctly. I want to read a csv txt file, structure of files are always the same only the rows are different. The name of the files is also different, I want to read and edit one file after the other. Read, edit, save. My Code is here:
public static class PersonService
public static List<Person> ReadFile(string filepath)
{
var lines = File.ReadAllLines(filepath);
var data = from l in lines.Skip(1)
let split = l.Split(';')
select new Person
{
Id = int.Parse(split[0]),
Name = split[1],
Age = int.Parse(split[2]),
Gender = (Gender)Enum.Parse(typeof(Gender), split[3])
};
return data.ToList();
}
}
public partial class Window2 : Window
public Window2()
{
InitializeComponent();
OpenFileDialog csv = new OpenFileDialog DataContext = PersonService.ReadFile(csv);
<Window x:Class="WpfApplication14.Window2"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="Window2" Height="300" Width="300">
<DataGrid AutoGenerateColumns="True"
ItemsSource="{Binding}"/>