Answer the question
In order to leave comments, you need to log in
How to display a one-dimensional array of numbers as a table?
Hello. There is a one-dimensional array of numbers. You need to display it as a table with a fixed number of columns.
For example, there is an array {1, 2, 3, 4, 5, 6, 7, 8}.
In xaml, it should be presented in this form:
1 2 3 4
5 6 7 8
I don’t even know which way to dig.
Answer the question
In order to leave comments, you need to log in
The easiest way is to dig in the direction of "make a two-dimensional array from a one-dimensional one, and bind it to xaml".
The idea in general is that it's easier to prepare the data for the UI (more often, much easier) than to suffer to adjust the UI for the raw data. Even a layer in the form of a VM in the MVVM pattern was invented for this.
Well, for example, like this:
int _width = 4;
string formatArray(IEnumerable<int> numbers)
{
var output = string.Empty;
var skip = 0;
while (skip <= numbers.Count)
{
output += string.Join(numbers.Skip(skip).Take(_width), " ") + "\n";
skip += width;
}
return output;
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question