Skip to content

Enhance trimming experiences for Frame.Navigate() with [DynamicallyAccessedMembers] #710

@davidxuang

Description

@davidxuang

I tested my app with AOT today and found that it might be helpful to annotate the sourcePageType parameter with [DynamicallyAccessedMembers]:

public bool Navigate(Type sourcePageType, object parameter, NavigationTransitionInfo infoOverride)
{
return NavigateCore(new PageStackEntry(sourcePageType, parameter,
infoOverride), NavigationMode.New);
}
/// <summary>
/// Causes the Frame to load content represented by the specified Page, also passing a parameter to be
/// interpreted by the target of the navigation.
/// </summary>
/// <param name="sourcePageType">The page (IControl) to navigate to, specified as a type reference to its class type, or
/// if a <see cref="NavigationPageFactory"/> this can be any type (e.g., a ViewModel)</param>
/// <param name="parameter">The navigation parameter to pass to the target page; must have a basic type
/// (string, char, numeric, or GUID) to support parameter serialization using GetNavigationState.</param>
/// <param name="navOptions">Options for the navigation, including whether it is recorded in the navigation stack
/// and what transition animation is used.</param>
/// <returns><c>false</c> if a <see cref="NavigationFailed"/> event handler has set Handled to true;
/// otherwise, <c>true</c>.</returns>
public bool NavigateToType(Type sourcePageType, object parameter, FrameNavigationOptions navOptions) =>
NavigateCore(new PageStackEntry(sourcePageType, parameter, navOptions?.TransitionInfoOverride),
NavigationMode.New, navOptions);

The minimal configuration could be [DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicParameterlessConstructor)], and this is enough for my project to work. Not sure if [DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.All)] is neccessary.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions