示例#1
0
 protected override void OnViewChanging(View view)
 {
     base.OnViewChanging(view);
     Active.SetItemValue("AutoCreatableObject", false);
     if (view != null && view is ObjectView)
     {
         AutoCreatableObjectAttribute attribute = ((ObjectView)view).ObjectTypeInfo.FindAttribute <AutoCreatableObjectAttribute>(true);
         if (attribute != null)
         {
             Active.SetItemValue("AutoCreatableObject", true);
         }
     }
 }
示例#2
0
 private void application_CustomProcessShortcut(object sender, CustomProcessShortcutEventArgs e)
 {
     if (e.Shortcut != null && !string.IsNullOrEmpty(e.Shortcut.ViewId))
     {
         IModelView modelView = Application.FindModelView(e.Shortcut.ViewId);
         if (modelView is IModelObjectView)
         {
             ITypeInfo typeInfo = ((IModelObjectView)modelView).ModelClass.TypeInfo;
             AutoCreatableObjectAttribute attribute = typeInfo.FindAttribute <AutoCreatableObjectAttribute>(true);
             if (attribute != null && attribute.AutoCreatable)
             {
                 IObjectSpace objSpace = Application.CreateObjectSpace(typeInfo.Type);
                 object       obj;
                 if (typeof(XPBaseObject).IsAssignableFrom(typeInfo.Type) ||
                     (typeInfo.IsInterface && typeInfo.IsDomainComponent))
                 {
                     obj = objSpace.FindObject(typeInfo.Type, null);
                     if (obj == null)
                     {
                         obj = objSpace.CreateObject(typeInfo.Type);
                     }
                 }
                 else
                 {
                     if (typeInfo.Type == typeof(WelcomeObject))
                     {
                         obj = WelcomeObject.Instance;
                     }
                     else
                     {
                         obj = Activator.CreateInstance(typeInfo.Type);
                     }
                 }
                 //obj = typeof(BaseObject).IsAssignableFrom(typeInfo.Type) ? objSpace.CreateObject(typeInfo.Type) : Activator.CreateInstance(typeInfo.Type);
                 DetailView detailView = Application.CreateDetailView(objSpace, obj, true);
                 if (attribute.ViewEditMode == ViewEditMode.Edit)
                 {
                     detailView.ViewEditMode = DevExpress.ExpressApp.Editors.ViewEditMode.Edit;
                 }
                 e.View    = detailView;
                 e.Handled = true;
             }
         }
     }
 }