Schematic Editor: Total page count variable is not properly initialised until switching schematic sheets

Description

When using a schematic with multiple sheets, and a worksheet template that includes page numbers (e.g. a text field that contains the text Page ${#} / ${##}), the latter variable is not properly initialised until one switches away from the root sheet to another sheet. All subsequent sheets, including the root sheet when you switch back, correctly render with the total number of pages printed after this point.

wks

Steps to reproduce

  1. Have a worksheet template that has page numbers (see above)
  2. Have a schematic that consists of multiple pages (e.g. sub-sheets)
  3. Open the KiCad project, and open the schematic editor from the project manager
  4. Observe that the worksheet says Page 1 / 1 (if you use the text from the description above)
  5. Switch to a schematic sub-sheet and back (PgDn, PgUp)
  6. Observe that the worksheet now renders the correct number of pages in that text field (e.g. Page 1 / 2)

KiCad Version

Application: KiCad Drawing Sheet Editor x64 on x64

Version: 7.0.9, release build

Libraries:
	wxWidgets 3.2.3
	FreeType 2.12.1
	HarfBuzz 8.2.1
	FontConfig 2.14.2
	libcurl/8.4.0-DEV Schannel zlib/1.3

Platform: Windows 10 (build 19045), 64-bit edition, 64 bit, Little endian, wxMSW

Build Info:
	Date: Nov  5 2023 19:26:40
	wxWidgets: 3.2.3 (wchar_t,wx containers)
	Boost: 1.83.0
	OCC: 7.7.1
	Curl: 8.4.0-DEV
	ngspice: 41
	Compiler: Visual C++ 1936 without C++ ABI

Build settings:
	KICAD_SPICE=ON