The crash is caused by a data binding failure on the details page. In UWP, binding expressions are evaluated at runtime via reflection; if a binding path is wrong (for example, a property name is misspelled, the DataContext is null, or the type doesn’t match), the framework can throw and terminate the app when navigating to that page.
To diagnose and fix it in Visual Studio for a UWP app:
- Check the binding paths on the details page
- Open the XAML for the book-details page.
- For each binding, verify that:
- The property name in
Path=... (or implicit path) exactly matches a public property on the view model or model (case-sensitive).
- The
DataContext of the page (or the control) is set to an object that actually has those properties.
- Common issues:
-
SelectedBook.Title vs Title when the DataContext is already the selected book.
- Binding to a field instead of a property (must be public properties for data binding).
- Verify DataContext is set correctly
- Ensure the details page’s
DataContext is assigned before the page loads:
- If the DataContext is null, any binding like
{Binding Title} will fail.
- Use XAML binding diagnostics in Visual Studio
- Run the app under the debugger.
- Open the XAML Binding Failures window (Visual Studio 2019 16.8+ or Visual Studio 2022).
- Navigate to the details page and watch for binding failures such as:
- “Binding: Path not found”
- “Cannot convert value of type … to type …”
- Each entry shows the exact binding expression and target, so it’s possible to correct the specific property name or type.
- Use
{x:Bind} where possible
- If using
{Binding}, consider switching to {x:Bind} for the details page:
-
{x:Bind} is compile-time checked and generates code, so invalid paths are caught at build time instead of causing runtime crashes.
- When a property is renamed, the compiler will fail if bindings aren’t updated.
- Turn on Break On Unhandled Exceptions
- In Visual Studio, enable Break On Unhandled Exceptions.
- When the app crashes on navigation to the details page, the debugger will break at the offending binding-generated code.
- Inspect the Call Stack to see which binding expression caused the exception.
- Check for .NET Native metadata issues (if using reflection-heavy bindings)
- If the app is compiled with the .NET Native toolchain and uses reflection-based binding to view models, a
MissingMetadataException can occur when metadata for a view model is removed.
- In that case, add the appropriate runtime directive (rd.xml) or apply
Windows.UI.Xaml.Data.BindableAttribute to the view model properties so that the metadata is preserved.
By systematically checking the DataContext, verifying each binding path, and using the XAML binding diagnostics and debugger, the specific binding that causes the crash on the details page can be identified and corrected.
References: