游戏技术文章

XAF-如何改变列表点击时的默认行为

时间:2017-3-16 16:39:48  作者:棋牌资源网  来源:棋牌资源网  查看:7931  评论:0
内容摘要:在 Windows 窗体应用程序中,按下回车或双击列表会打开默认的详细视图。在 ASP.NET Web 应用程序中,单击对象时执行此操作。这一行为是由 ListViewProcessCurrentObjectContro...
 Windows 窗体应用程序,按下回车或双击列表会打开默认的详细视图

 ASP.NET Web 应用程序单击对象执行操作

行为 ListViewProcessCurrentObjectController 的 ListViewProcessCurrentObjectController.ProcessCurrentObjectAction 按钮所定义

可以操作替换自定义简单操作。下面演示如何执行操作

示例代码在这里。

有下面的BO定义,地址记录。

复制代码
[DefaultClassOptions, ImageName("BO_Contact")]
public class AddressBookRecord : BaseObject {
    public AddressBookRecord(Session session) : base(session) { }
    private string name;
    public string Name {
        get { return name; }
        set { SetPropertyValue("Name", ref name, value); }
    }
    private string email;
    public string Email {
        get { return email; }
        set { SetPropertyValue("Email", ref email, value); }
    }
    private string phoneNumber;
    public string PhoneNumber {
        get { return phoneNumber; }
        set { SetPropertyValue("PhoneNumber", ref phoneNumber, value); }
    }
}
复制代码

现在并为AddressBookRecord 对象操作加一个WriteMailController,并填加 WriteMail Action这个操作将调用最终用户的计算机的 MailTo 协议相关联程序。说白了就是发个邮件,调用邮件客户端。

复制代码
using System.Diagnostics;
// ... 
public class WriteMailController : ViewController {
    private SimpleAction writeMailAction;
    public WriteMailController() {
        TargetObjectType = typeof(AddressBookRecord);
        writeMailAction = new SimpleAction(this, "WriteMail", PredefinedCategory.Edit);
        writeMailAction.ToolTip = "Write e-mail to the selected address book record";
        writeMailAction.SelectionDependencyType = SelectionDependencyType.RequireSingleObject;
        writeMailAction.ImageName = "BO_Contact";
        writeMailAction.Execute += writeMailAction_Execute;
    }
    void writeMailAction_Execute(object sender, SimpleActionExecuteEventArgs e) {
        AddressBookRecord record = (AddressBookRecord)e.CurrentObject;
        string startInfo = String.Format(
            "mailto:{0}?body=Hello, {1}!%0A%0A", record.Email, record.Name);
        Process.Start(startInfo);
    }
}
复制代码

默认情况下,只有选中了列表中的一条记录后,再点击上面我们填加的按钮,才会执行调用邮件客户端的动作。

下面,我们演示,在win中双击列表,即执行上面的动作。

复制代码
using DevExpress.ExpressApp.SystemModule;
// ... 
public class WriteMailController : ViewController {
    // ... 
    private ListViewProcessCurrentObjectController processCurrentObjectController;
    protected override void OnActivated() {
        base.OnActivated();
        processCurrentObjectController =
            Frame.GetController<ListViewProcessCurrentObjectController>();
        if (processCurrentObjectController != null) {
            processCurrentObjectController.CustomProcessSelectedItem +=
                processCurrentObjectController_CustomProcessSelectedItem;
        }
    }
    private void processCurrentObjectController_CustomProcessSelectedItem(object sender, CustomProcessListViewSelectedItemEventArgs e) {
        e.Handled = true;
        writeMailAction.DoExecute();
    }
    protected override void OnDeactivated() {
        if (processCurrentObjectController != null) {
            processCurrentObjectController.CustomProcessSelectedItem -= 
                processCurrentObjectController_CustomProcessSelectedItem;
        }
        base.OnDeactivated();
    }
}
复制代码

下面是效果:

这时你会发现,你没办法修改记录了,即详细视图没办法显示出来了。下面代码来解决这样的问题,即,加个控制器,实现这些功能。

复制代码
using DevExpress.ExpressApp.SystemModule;
// ... 
public class EditAddressBookRecordController : ViewController<ListView> {
    public EditAddressBookRecordController() {
        TargetObjectType = typeof(AddressBookRecord);
        SimpleAction editAddressBookRecordAction = 
            new SimpleAction(this, "EditAddressBookRecord", PredefinedCategory.Edit);
        editAddressBookRecordAction.ImageName = "Action_Edit";
        editAddressBookRecordAction.SelectionDependencyType = 
            SelectionDependencyType.RequireSingleObject;
        editAddressBookRecordAction.Execute += editAddressBookRecordAction_Execute;
    }
    void editAddressBookRecordAction_Execute(object sender, SimpleActionExecuteEventArgs e) {
        ListViewProcessCurrentObjectController.ShowObject(
            e.CurrentObject, e.ShowViewParameters, Application, Frame, View);
    }
}
复制代码

注意:在web中没这个问题,所以不用管。

标签:XAF-如何改变列表点击时的默认行为 

欢迎加入VIP,【VIP售价:只要288元永久VIP会员】畅享商业棋牌游戏程序下载,点击开通!

下载说明


☉本站所有源码和资源均由站长亲自测试-绝对保证都可以架设,运营!
☉如源码和资源有损坏或所有链接均不能下载,请告知管理员,

☉本站软件和源码大部分为站长独资,资源购买和收集,放心下载!

☉唯一站长QQ:1004003180  [人格担保-本站注重诚信!]

☉购买建议E-mail:1004003180@qq.com   源码收购 E-mail:1004003180@qq.com    

☉本站文件解压密码  【文章内都自带解压密码,每个密码不同!】


本站提供的所有源码,均来源站长提供,仅学习交流 浙ICP备09009969号

由此产生不良后果和法律责任与本站无关,如果侵犯了您的版权,请来信告知 1004003180@qq.com 将及时更正和删除! 

Copyright © 2008-2021 棋牌资源网,你身边的棋牌资源下载站    All Rights Reserved