pick appropriate .json data in Tab (ShellContext)

Eduard Kaufmann 291 Reputation points
2025-03-12T09:25:58.7233333+00:00

As a senior+ hobby developer I'm stuck. I know - whoever helps - this is not what this GitHub forum is for and, I know, this is an imposition!

Anyway, hopefully somebody has some time and is willing to help, thank you.

my APP: https://github.com/edikaufmann/RandoJson

In the process of changing the data input from .cs to .json I'm stuck.

Reason for changing: with .cs I have to compile every time the data is changing; therefore, I have a routine which gets the data dynamically.

What is working:

when clicking 'Get Randos' on the first screen all is ok!

On this first screen you also see some Tabs defined in 'AppShell.xaml'.

In fact I would like to use these tabs to open the 'MainPage.xaml' with the appropriate .json file like: 'VARHaute.Json', 'SiouBlanc.Json', 'AlpesdeHauteProvence.Json'.

e.g. below tab should shows the code for 'VARHaute':

<ShellContent Title="VARHaute"

          ContentTemplate="{DataTemplate views:MainPage}"

          Style="{StaticResource VARHauteShell}"

          Route="VARHaute"/>

Where I'm stuck:

when clicking this tab how do I tell (in ShellContent) to use the data for 'VARHaute(.Json)'?

How do I pass a parameter e.g.'VARHaute' to 'Services.RandoService.cs' ?

Might be I miss a very simple Maui 'routine'!

right now in code 'Services.RandoService.cs' I hardcode 'VARHaute' like:

public async Task<List<Rando>> GetRandos()

.

.

// how to set fileName dynamically ?????????????????????????????????

string fileName = "VARHaute";

// how to set fileName dynamically ???????????????????????????????

// comment; fileName = "VARHaute" or "SiouBlanc" or "AlpesdeHauteProvence"

var response = await httpClient.GetAsync("https://randopro.org/MyUploads/Data/" + fileName + ".json");

if (response.IsSuccessStatusCode)

{

 randoList = await response.Content.ReadFromJsonAsync<List<Rando>>();

 

}

.NET MAUI
.NET MAUI
A Microsoft open-source framework for building native device applications spanning mobile, tablet, and desktop.
3,998 questions
0 comments No comments
{count} votes

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.