I'm creating a UI that visualizes som parts of a simulator. I am supposed to present some of the values in a table format, however I'm unable to get the table to update continuously when its already initialized (it initialized with the correct values, but is then static when you look at it, so you have to go to another page and then back to get the table to update) This is the code:
<Page x:Class="SimulatorUI.RawDataPage"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:local="clr-namespace:SimulatorUI"
mc:Ignorable="d"
d:DesignHeight="950" d:DesignWidth="750"
Title="RawDataPage">
<DataGrid Name="dataTable" MinWidth="500" Margin="10 10 10 10" HorizontalContentAlignment="Center" HorizontalAlignment="Center"/>
</Page>
And the c# code looks like this
public partial class RawDataPage : Page
{
List<TankModule> tankList;
public RawDataPage(List<TankModule> list)
{
tankList = list;
InitializeComponent();
List<displayModule> data = loadTable();
dataTable.ItemsSource = data;
Task.Run(() => updateLoop());
}
public List<displayModule> loadTable()
{
List<displayModule> modules = new List<displayModule>();
foreach(TankModule tank in tankList)
{
modules.Add(new displayModule(tank));
}
return modules;
}
internal async Task updateLoop()
{
for (; ; )
{
dataTable.ItemsSource = null;
dataTable.ItemsSource = loadTable();
await Task.Delay(1000);
}
}
}