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

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

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

2019-11-11 01:39:49
字體:
來源:轉載
供稿:網友

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

 


發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 舟曲县| 天台县| 南通市| 芜湖市| 宁强县| 绩溪县| 保康县| 漾濞| 罗城| 梅州市| 东平县| 乌什县| 和平县| 焉耆| 宜宾县| 榆社县| 三原县| 新安县| 芦山县| 观塘区| 杨浦区| 恩施市| 临洮县| 磴口县| 宜丰县| 梅河口市| 武穴市| 明水县| 买车| 阿坝县| 奉贤区| 息烽县| 嵊泗县| 丽江市| 康平县| 米易县| 青海省| 会同县| 舞钢市| 时尚| 泾川县|