域名申请 网站建设,安阳做网站的地方,新闻类的网站如何做优化,高端食品wordpress需求#xff1a;
有一个F0View主页面入口#xff0c;三个子页面#xff08;First.xaml/Second.xaml/Third.xaml#xff09;用Frame默认加载第一个页面 First.xaml。实现三个页面之间顺序跳转#xff0c;并且每个页面只初始化一次。
实现#xff1a;
1#xff0c;将三…需求
有一个F0View主页面入口三个子页面First.xaml/Second.xaml/Third.xaml用Frame默认加载第一个页面 First.xaml。实现三个页面之间顺序跳转并且每个页面只初始化一次。
实现
1将三个页面放入统一容器中 public class FOPluginModule{public static ServiceProvider ServiceProvider { get; set; }public static void ConfigureServices(){var serviceCollection new ServiceCollection();serviceCollection.AddSingletonF0Instruction();serviceCollection.AddSingletonF0Procedure();serviceCollection.AddSingletonF0Result();ServiceProvider serviceCollection.BuildServiceProvider();}}
2创建单例封装主视图中的Frame控件
using System.Windows.Controls;namespace WDM.MR.WMC.Plugins.F0.Service
{public class F0MainFrameSingleton{public Frame Frame { get; set; }private static readonly object LockObj new object();private static F0MainFrameSingleton _instance;public static F0MainFrameSingleton Instance{get{if (_instance null){lock (LockObj){if (_instance null){_instance new F0MainFrameSingleton() ;}}}return _instance;}}}
}
3将主页面Frame实例化在F0ViewModel中 public F0ViewModel(Frame mainFrame)
{FOPluginModule.ConfigureServices();F0MainFrameSingleton.Instance.Frame mainFrame;
}
4在三个子页面的ViewMode里直接引用上面的单例类注册导航事件然后调转页面直接使用封装的单例类中的Frame的Navgation方法
下面是以其中一个页面为例其他子页面同样的方法ExtraData的值可以任意定义。 1跳转方法
[RelayCommand]
private void OnNextPage()
{F0MainFrameSingleton.Instance.Frame.Navigate(FOPluginModule.ServiceProvider.GetService(typeof(F0Procedure)), Ins);
}
2导航事件具体的逻辑处理
public F0InstructionViewModel()
{F0MainFrameSingleton.Instance.Frame.Navigated Ins_Navigated;F0MainFrameSingleton.Instance.Frame.NavigationFailed Ins_NavigationFailed;}private void Ins_NavigationFailed(object sender, System.Windows.Navigation.NavigationFailedEventArgs e)
{throw new NotImplementedException();
}private void Ins_Navigated(object sender, System.Windows.Navigation.NavigationEventArgs e)
{if(e.ExtraData ! null){Console.WriteLine(chenggong);}
}
以上可完成完整的跳转 用到哪学到哪记到哪