using XFEExtension.NetCore.WinUIHelper.Implements.Services; using XFEExtension.NetCore.WinUIHelper.Interface.Services; using XFEExtension.NetCore.WinUIHelper.Utilities.Additions; namespace XFEExtension.NetCore.WinUIHelper.Utilities.Helper; /// /// 导航帮助类 /// public static class NavigationHelper { /// /// 设置目标页面的导航参数 /// /// 目标页面 /// 导航参数 public static void SetParameter(this Page page, object? parameter) => page.GetType().GetProperty("Parameter")?.SetValue(page, parameter); /// /// 获取导航参数 /// /// 目标页面 /// 导航参数 public static object? GetParameter(this Page page) { var viewModelProperty = page.GetType().GetProperty("ViewModel"); var parameterProperty = viewModelProperty?.PropertyType.GetProperties().FirstOrDefault(property => property.PropertyType.Name == typeof(IAutoNavigationParameterService).Name); return parameterProperty?.PropertyType.GetInterfaces()[0].GetProperty("Parameter")?.GetValue(parameterProperty.GetValue(viewModelProperty?.GetValue(page))) ?? page.GetType().GetProperty("Parameter")?.GetValue(page); } /// /// 获取导航目标附加值 /// /// 导航项 /// 导航目标 public static string? GetNavigateTo(this NavigationViewItem navigationViewItem) => navigationViewItem.GetValue(NavigationAddition.NavigateToProperty).ToString(); /// /// 获取导航参数附加值 /// /// 导航项 /// 导航参数 public static object? GetNavigationParameter(this NavigationViewItem navigationViewItem) => navigationViewItem.GetValue(NavigationAddition.NavigateParameterProperty); }