问题
var displayRegion= ApplicationView.GetForCurrentView().GetDisplayRegions()
In some devices, I am getting this exception, System.InvalidCastException: 'Unable to cast object of type 'Windows.UI.ViewManagement.ApplicationView' to type 'Windows.UI.ViewManagement.IApplicationView9'. How to avoid this exception?
回答1:
The GetDisplayRegions
API was introduced in Windows 10, version 1903 (introduced in 10.0.18362.0) (see Docs). This means you have to first check if the API is present on the current device using APIInformation.IsMethodPresent.
来源:https://stackoverflow.com/questions/62556132/system-invalidcastexception-unable-to-cast-object-of-type-applicationview-to