关于我们

质量为本、客户为根、勇于拼搏、务实创新

< 返回新闻公共列表

Caliburn.Micro框架之Action Convertions

发布时间:
首先新建一个项目,名称叫Caliburn.Micro.ActionConvertions 然后删掉MainWindow.xaml 然后去app.xaml删掉StartupUri这行代码 其次,安装Caliburn.Micro,Caliburn.Micro.Core,这两个Nuget包,如下图 然后新建一个类Bootstrapper,这个类是引导作用,比如重写了首页的引导,ioc注入等 然后在项目中新建ViewModels,Views,在Views中添加窗口ShellView,在ViewModels中添加类ShellViewModel,如下图 public class Bootstrapper : BootstrapperBase { private SimpleContainer container; public Bootstrapper() { Initialize(); } protected override void Configure() { container = new SimpleContainer(); container.Singleton(); container.PerRequest(); } protected override void OnStartup(object sender, StartupEventArgs e) { DisplayRootViewFor(); } protected override object GetInstance(Type service, string key) { return container.GetInstance(service, key); } protected override IEnumerable GetAllInstances(Type service) { return container.GetAllInstances(service); } protected override void BuildUp(object instance) { container.BuildUp(instance); } }   再继续新建一个类TaskHelper TaskHelper类的内容入下 修改ShellViewModel类 public class ShellViewModel : Screen { private string output; public void Clear() => Output = String.Empty; public void SimpleSayHello() => Output = "Hello from Caliburn.Micro"; public void SayHello(string name) => Output = $"Hello {name}"; public bool CanSayHello(string name) => !String.IsNullOrEmpty(name); public Task SayGoodbyeAsync(string name) { Output = $"Goodbye {name}"; return TaskHelper.FromResult(true); } public bool CanSayGoodbye(string name) => !String.IsNullOrEmpty(name); public string Output { get { return output; } set { Set(ref output, value); } } } 然后修改ShellView页面的布局