SmartClient Software factory中的Composite UI Application Block(Cab)技术了解(三):UIElement

UIElement描述和实例

       UIElementSCSF中是只视图上的控件,包括MENU控件,TOOLBAR控件以及自定义控件等等,这里重点是说一说自定义控件部分,因为在Symphony中如果要统一视图风格,自定义控件是必不可少的技术,而制作自定义控件在SCSF中需要先分别继承并实现两个接口:UIElementAdapterIUIElementAdapterFactory。这样才能在SCSF中进行加载和共享。

1.         利用SCSF创建一个Module并创建一个用户控件,同时创建两个类并分别继承UIElementAdapterIUIElementAdapterFactory两个接口。

2.4.1

2.         AdaptorFactory两个类中分别加入如下代码:

    public class CustomerUIElementAdaptor : UIElementAdapter<String>

    {

        CustomerUIElement _uiObj;

        public CustomerUIElementAdaptor(CustomerUIElement uiobj)

        {

            this._uiObj = uiobj;

        }

        protected override string Add(string uiElement)

        {

            this._uiObj.Text = uiElement;

            return uiElement;

        }

 

        protected override void Remove(string uiElement)

        {

            string ss = this._uiObj.Text;

            if (ss.Contains(uiElement))

            {

                ss.Replace(uiElement, "");

            }

        }

}

    public class CustomerUIElementFactory : IUIElementAdapterFactory

    {

        #region IUIElementAdapterFactory 成员

 

        public IUIElementAdapter GetAdapter(object uiElement)

        {

            if (uiElement is CustomerUIElement)

            {

                return new CustomerUIElementAdaptor(uiElement as CustomerUIElement);

            }

            throw new ArgumentException("uiElement");

           

        }

 

        public bool Supports(object uiElement)

        {

            return uiElement is CustomerUIElement;

        }

 

        #endregion

    }

剩下把控件视图设计好。这样一个自定义控件就已经完成,接下来就是如何在其他视图中使用该自定义控件了。

3.         Module中的一个VIEW中添加该自定义控件:

2.4.2

增加一个类ModuleActions,并添加相关代码:

public class ModuleActions

    {

        private WorkItem _workItem = null;

 

        [ServiceDependency]

        public WorkItem WorkItem

        {

            get { return _workItem; }

            set { _workItem = value; }

        }

 

        [Action(ActionNames.ShowCustomerUIElement)]

        public void showCustomerUiElement(object caller, object target)

        {

            UIExtensionSite site = WorkItem.UIExtensionSites[UIExtensionSiteNames.CustomerUiElement];

            String ss = "test the customer uielement block";

            site.Add(ss);

        }

        [Action(ActionNames.ViewCustomerUIElement)]

        public void addCustomerUiElement(object caller, object target)

        {

            UiElementView view = WorkItem.Items.AddNew<UiElementView>();

            WorkItem.Workspaces[WorkspaceNames.LayoutUIElementView].Show(view);

            WorkItem.UIExtensionSites.RegisterSite(UIExtensionSiteNames.CustomerUiElement, view.customerView);

        

        }

    }

在类ModuleController中添加代码:

            WorkItem.Items.AddNew<ModuleActions>();

            ActionCatalogService.Execute(ActionNames.ViewCustomerUIElement, WorkItem, this, null);

            ActionCatalogService.Execute(ActionNames.ShowCustomerUIElement, WorkItem, this, null);

在类SmartClientApplication中增加相关服务代码:

            RootWorkItem.Services.AddOnDemand<ActionCatalogService, IActionCatalogService>();

            IUIElementAdapterFactoryCatalog catalog = RootWorkItem.Services.Get<IUIElementAdapterFactoryCatalog>();

            catalog.RegisterFactory(new CustomerUIElementFactory());

在配置文件中配置好后直接运行,就可得到如图 2.4.3 结果。

2.4.3

 

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值