So after a bit of a wrangle I managed to write some code that would allow me to read a text file, split it and place it into an array and then bind that array to text boxes - it isn't great, as there are 60 entries in the Array, and splitting them into the textboxes was a pain - but it works. I am able to populate all text boxes with the correct data from a text file and the numbers in the text file do not change - it is always 60.
I was then able to bind a text box to the output in xaml like so:
This is all in a grid called TimeKeeper.
There are 5 entries per line, so 0 & 5 is the first of x and then the second of x.
So trying to follow the proper course, rather than have that in my Main Window code, I created a class, and put the logic in the class.
Then in the main window
Using breakpoints, I can see that Entries has 60 entries, as it is supposed to have, and the binding is the same - I just don't know why it isn't working. I tried
as it was previously, but that didn't work either.
Am I missing something that I now need to bind this after moving the logic to a class?
C#:
List<string> Entries = new List<string>();
string DS1 = fn.CombinedName("DataSet1.txt");
if (File.Exists(DS1))
{
var lines = File.ReadAllLines(DS1);
Entries= lines.SelectMany(x => x.Split(new[]
{
','
}, StringSplitOptions.None)).ToList();
}
TimeKeeper.DataContext = this;
I was then able to bind a text box to the output in xaml like so:
C#:
Text="{Binding Entries [0]}"
Text="{Binding Entries [5]}"
This is all in a grid called TimeKeeper.
There are 5 entries per line, so 0 & 5 is the first of x and then the second of x.
So trying to follow the proper course, rather than have that in my Main Window code, I created a class, and put the logic in the class.
C#:
public class DataCollection
{
public List<string> Populate { get; set; }
FileName fn = new FileName();
public List<string> Entries()
{
string DS1 = fn.CombinedName("DataSet1.txt");
if (File.Exists(DS1))
{
var lines = File.ReadAllLines(DS1);
Populate = lines.SelectMany(x => x.Split(new[]
{
','
}, StringSplitOptions.None)).ToList();
}
return Populate;
}
}
Then in the main window
C#:
List<string> Entries = new List<string>();
private void Reload()
{
DataCollection dc = new DataCollection();
dc.Entries();
Entries = dc.Populate;
TimeKeeper.DataContext = Entries;
}
Using breakpoints, I can see that Entries has 60 entries, as it is supposed to have, and the binding is the same - I just don't know why it isn't working. I tried
C#:
TimerKeeper.DataContext = this;
as it was previously, but that didn't work either.
Am I missing something that I now need to bind this after moving the logic to a class?