国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 學院 > 開發設計 > 正文

Caliburn.Micro學習筆記(五)----協同IResult

2019-11-11 02:49:50
字體:
來源:轉載
供稿:網友

Caliburn.Micro學習筆記目錄

今天說一下協同IResult

看一下IResult接口

復制代碼
 /// <summary>    /// Allows custom code to execute after the return of a action.    /// </summary>    public interface IResult {        /// <summary>        /// Executes the result using the specified context.        /// </summary>        /// <param name="context">The context.</param>        void Execute(ActionExecutionContext context);        /// <summary>        /// Occurs when execution has completed.        /// </summary>        event EventHandler<ResultCompletionEventArgs> Completed;    }復制代碼

Execute方法里寫你要執行的事件,在最后執行事件Completed這是一定要執行的,不然會無法執行后繼的yield部分

Execute 方法有一個ActionExecutionContext參數,這個參數與建立UI相關的IResult實現中

非常有用。它能提供的功能如下

復制代碼
public class ActionExecutionContext{    public ActionMessage Message;    public FrameworkElement Source;    public object EventArgs;    public object Target;    public DependencyObject View;    public MethodInfo Method;    public Func<bool> CanExecute;    public object this[string key];}復制代碼

Message: 造成這 IResult 的調用原始 ActionMessage。

Source: FrameworkElement 觸發執行的行動。

EventArgs: 與行動的觸發器相關聯的任何事件參數。

Target: 在實際的操作方法存在的類實例。

View: 與目標關聯的視圖。

Method: MethodInfo 指定要在目標實例上調用的方法。

CanExecute: 一個函數,如果操作可被調用、 虛假否則返回 true。

key index: 一個地方來存儲/檢索它可以對框架的擴展所使用的任何附加元數據。

做一個小Demo

源碼:CaliburnIresult.rar

由于這個例子很簡單我們把bootstrapper也寫簡單一些

    class HelloBootstrapper : Bootstrapper<MyViewModel>    {    }

這樣就可以 了新建一下Loader類去實現IResult接口

復制代碼
    public class Loader : IResult    {        readonly string _str;        public Loader(string str)        {            _str = str;        }        public void Execute(ActionExecutionContext context)        {            MessageBox.Show(_str + context.View);            Completed(this, new ResultCompletionEventArgs());//這個方法一定要加到這里,這個方法完成后才會執行后邊的方法        }        public event EventHandler<ResultCompletionEventArgs> Completed = (sender, args) =>        {            MessageBox.Show(((Loader)sender)._str );        };    }復制代碼

前臺我們就放一下button就可以

復制代碼
<Window x:Class="CaliburnIresult.MyView"        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/PResentation"        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"        xmlns:cal="http://www.caliburnproject.org"        Title="MyView" Height="300" Width="300">    <Grid>        <Button Content="IResult"  cal:Message.Attach="MyIResultClick"/>    </Grid></Window>復制代碼

在ViewModel里我們看一下它的方法實現

        public IEnumerable<IResult> MyIResultClick()        {            yield return new Loader("load.....");            yield return new Loader("Ok!");        }

 源碼:CaliburnIresult.rar

 


發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 什邡市| 金门县| 庆安县| 司法| 墨江| 长阳| 邢台县| 忻城县| 湘潭市| 温宿县| 抚顺县| 日照市| 三门县| 淮南市| 鄂托克前旗| 遂川县| 新郑市| 阿克苏市| 澄城县| 巴东县| 霍山县| 贵港市| 温州市| 砚山县| 临沭县| 阳西县| 托克逊县| 康保县| 永宁县| 海兴县| 库伦旗| 竹山县| 吐鲁番市| 雷州市| 湖北省| 法库县| 上犹县| 丹棱县| 瑞安市| 白山市| 阳原县|