Repository navigation
docs: Add ViewMap and DataContext troubleshooting guide with navigation lifecycle deep dive - #2984
carldebilly with Copilot wants to merge 5 commits into
Conversation
Co-authored-by: carldebilly <[email protected]>
|
|
Co-authored-by: carldebilly <[email protected]>
|
@copilot Please spend more time explaining the nativation lifecycle. You can even use a mermaid diagram if you like. Take time to valide everything with the code base and check if other part of the documentation should be updated or refer this page. |
There was a problem hiding this comment.
Pull request overview
This PR adds a comprehensive troubleshooting guide for ViewMap and DataContext issues in Uno.Extensions Navigation. The documentation addresses a significant gap by providing developers with systematic debugging steps and explanations of the internal mechanisms.
Key changes:
- New troubleshooting document explaining ViewMap's internal type registration and DataContext assignment lifecycle
- Six-step diagnostic workflow with practical code examples
- Coverage of common issues (null DataContext, binding failures, type mismatches, manual assignment conflicts)
- Advanced debugging techniques including custom handlers and visual tree inspection
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
| doc/Learn/Navigation/toc.yml | Added table of contents entry for the new troubleshooting guide |
| doc/Learn/Navigation/Troubleshooting-ViewMap-DataContext.md | New comprehensive troubleshooting guide covering ViewMap mechanics, DataContext lifecycle, common issues, debugging techniques, and best practices |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
… address review feedback Co-authored-by: carldebilly <[email protected]>
Added comprehensive "Navigation Lifecycle Deep Dive" section with:
Also added cross-references to this troubleshooting guide in HowTo-DefineRoutes and NavigationOverview. (9c4142f) |
|
@copilot |
Co-authored-by: carldebilly <[email protected]>
PR Type
What is the current behavior?
Developers debugging null
DataContextissues lack documentation on:What is the new behavior?
New troubleshooting guide (
Troubleshooting-ViewMap-DataContext.md) documents:Internal Mechanisms
ViewMap→ DI container → view-viewmodel mappingview.DataContext = viewModelinFrameworkElementExtensions.csNavigation Lifecycle Deep Dive
Diagnostic Process
Six-step troubleshooting workflow:
Common Issues
INotifyPropertyChangedimplementationDeveloper Tools
NavigationRequestHandlerfor loggingLoadedevent inspectionDocumentation Cross-References
HowTo-DefineRoutes.mdandNavigationOverview.mdPR Checklist
Screenshots Compare Test Runresults.Other information
Documentation follows conventional commits format. Changes based on code review feedback:
NOTE:comments for broader renderer compatibilitytypeof(MainPage)instead of page instanceOriginal prompt
This section details on the original issue you should resolve
<issue_title>[Documentation] [Navigation] ViewMap/DataContext Troubleshooting and Internal Mechanism Documentation</issue_title>
<issue_description>## Problem Statement
I recently spent significant time debugging what seemed like a simple issue: a button in my XAML wasn't responding to clicks. The bindings appeared correct, the UI rendered fine, but nothing worked. The root cause was that
DataContextwas null, and the current documentation doesn't adequately explain:ViewMapactually works internallyDataContextgets assignedThe current documentation leaves developers without clear guidance on these critical aspects of the navigation system.
My Debugging Journey
Here's what I had to figure out to solve this issue:
Attempt 1: Visual Debugging
Added a debug
TextBlockto display theDataContexttype:Result: Confirmed
DataContextwas NULL. But why?Attempt 2: Constructor Logging
Problem discovered:
Debug.WriteLine()doesn't appear in PowerShell background jobs. Had to switch toConsole.WriteLine().Result: Page constructor runs, but
DataContextis NULL afterInitializeComponent().Attempt 3: ViewModel Constructor Logging
Result: No log output on first launch. ViewModel was never created!
Attempt 4: Verify DI Registration
Checked
App.xaml.cs:Everything looked correct, but still didn't work.
Attempt 5: Hot Reload Test
Made a minor XAML change and saved the file.
BREAKTHROUGH: After Hot Reload:
Conclusion: ViewMap WORKS, but only after Hot Reload. There's an initialization timing issue on first app launch.
What's Missing from the Documentation
The current View and ViewModel page doesn't adequately cover:
1. How ViewMap Actually Works (Critical Gap)
Current state: Documentation says ViewMap "associates" a View with a ViewModel, but doesn't explain the mechanism.
What's needed: A clear explanation like:
Why it matters: Without this clarity, developers may assume they need to manually wire up DataContext, leading to incorrect implementations and confusion.
2. Troubleshooting Section (Critical Gap)
Current state: No troubleshooting guidance exists.
What's needed: A dedicated troubleshooting page covering:
Problem: DataContext is null, bindings don't work
Diagnostic Steps:
Verify DataContext in Page.Loaded:
Check BOTH registrations are present:
Verify ViewModel constructor is called:
If this log doesn't appear → DI registration issue or missing dependency.
Test with Hot Reload:
Why it matters: Without this guidance, developers are left without a clear path to diagnose and resolve issues.
3. DI + ViewMap Prerequisites (Critical Gap)...
💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.