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

首頁(yè) > 學(xué)院 > 開(kāi)發(fā)設(shè)計(jì) > 正文

Caliburn.Micro學(xué)習(xí)筆記(五)----協(xié)同IResult

2019-11-11 01:33:04
字體:
來(lái)源:轉(zhuǎn)載
供稿:網(wǎng)友

Caliburn.Micro學(xué)習(xí)筆記目錄

今天說(shuō)一下協(xié)同IResult

看一下IResult接口

復(fù)制代碼
 /// <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;    }復(fù)制代碼

Execute方法里寫你要執(zhí)行的事件,在最后執(zhí)行事件Completed這是一定要執(zhí)行的,不然會(huì)無(wú)法執(zhí)行后繼的yield部分

Execute 方法有一個(gè)ActionExecutionContext參數(shù),這個(gè)參數(shù)與建立UI相關(guān)的IResult實(shí)現(xiàn)中

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

復(fù)制代碼
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];}復(fù)制代碼

Message: 造成這 IResult 的調(diào)用原始 ActionMessage。

Source: FrameworkElement 觸發(fā)執(zhí)行的行動(dòng)。

EventArgs: 與行動(dòng)的觸發(fā)器相關(guān)聯(lián)的任何事件參數(shù)。

Target: 在實(shí)際的操作方法存在的類實(shí)例。

View: 與目標(biāo)關(guān)聯(lián)的視圖。

Method: MethodInfo 指定要在目標(biāo)實(shí)例上調(diào)用的方法。

CanExecute: 一個(gè)函數(shù),如果操作可被調(diào)用、 虛假否則返回 true。

key index: 一個(gè)地方來(lái)存儲(chǔ)/檢索它可以對(duì)框架的擴(kuò)展所使用的任何附加元數(shù)據(jù)。

做一個(gè)小Demo

源碼:CaliburnIresult.rar

由于這個(gè)例子很簡(jiǎn)單我們把bootstrapper也寫簡(jiǎn)單一些

    class HelloBootstrapper : Bootstrapper<MyViewModel>    {    }

這樣就可以 了新建一下Loader類去實(shí)現(xiàn)IResult接口

復(fù)制代碼
    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());//這個(gè)方法一定要加到這里,這個(gè)方法完成后才會(huì)執(zhí)行后邊的方法        }        public event EventHandler<ResultCompletionEventArgs> Completed = (sender, args) =>        {            MessageBox.Show(((Loader)sender)._str );        };    }復(fù)制代碼

前臺(tái)我們就放一下button就可以

復(fù)制代碼
<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>復(fù)制代碼

在ViewModel里我們看一下它的方法實(shí)現(xiàn)

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

 源碼:CaliburnIresult.rar

 


發(fā)表評(píng)論 共有條評(píng)論
用戶名: 密碼:
驗(yàn)證碼: 匿名發(fā)表
主站蜘蛛池模板: 呼图壁县| 兰坪| 兴宁市| 克拉玛依市| 安福县| 调兵山市| 酒泉市| 陆丰市| 甘泉县| 鹤山市| 达拉特旗| 金溪县| 深水埗区| 阿克苏市| 道真| 全南县| 屯留县| 和田县| 高青县| 长沙县| 安岳县| 荥阳市| 碌曲县| 双流县| 宾阳县| 吉木乃县| 拜城县| 本溪市| SHOW| 大余县| 军事| 肃南| 安达市| 遵化市| 余姚市| 绵阳市| 新郑市| 蓬溪县| 木里| 安乡县| 北川|