Add Dynamic Properties from SimpleAction

StatusIDPriorityType
Closed33336MajorQuestion
ProfileReply
gabossoloClient

Hi !

Could you please assist me on how to add dynamic properties from a SimpleAction and see them on my DetailView without reload the view?

Thank you!

Regards,

Replies

UserDescriptionPosted On
MariyaVoytovichAgent

Hello gabossolo!

You can see in the Feature Center demo how to add dynamic properties from SimpleAction.
This action describe in DynamicParametersViewController.
Feature Center code in the "C: \ Users \ Public \ Documents \ Xafari Framework v17.2.6011 Demos\FeatureCenter\CS" folder.

To see this action in action:
1. Open FeatureCenter.Win application
2. In navigation go to "DynamicProperties / DynamicPropertiesObject"
3. Open "Example" Object in list view.
4. Click "AddDynamicParameter" action.

Feel free to contact us if you need further assistance or have additional questions.

Regards,
Mariya
On behalf of Xafari Client Services Team

gabossoloClient

Hi Mariya !

Thanks for your reply.

Indeed, I want to add dynamic properties from the code without showing parameters in a pop-up Windows to the user.

addFlightStopAction.Execute += AddFlightStopActionOnExecute;

private void AddFlightStopActionOnExecute(object sender, SimpleActionExecuteEventArgs e)
{
_objectSpace = Application.CreateObjectSpace();
_defaultValueObject = _objectSpace.Xafari().CreateObject();
_defaultValueObject.Name = "FlightStop";
_defaultValueObject.PropertyType = typeof(Airport);
_defaultValueObject.AllowEdit = true;
_defaultValueObject.Value = null;
_defaultValueObject.DisplayName = "Stop 1";

...

Thanks!

MariyaVoytovichAgent

Hi!

This is a code example for adding a dynamic property to an object.

void mySimpleActionForDynamicParameter_Execute(object sender, SimpleActionExecuteEventArgs e)
{
var currentObject = View.CurrentObject as PersistentXafariBaseObject;
if (currentObject == null) return;
var _objectSpace = Application.CreateObjectSpace();
var myDefaultValueObject = _objectSpace.CreateObject();
myDefaultValueObject.Name = "myDinamicProperty";
myDefaultValueObject.PropertyType = typeof(DateTime);myDefaultValueObject.ValueDateTime = DateTime.Now;
currentObject.AddProperty(myDefaultValueObject.Name, myDefaultValueObject.PropertyType);

currentObject.Session.CommitTransaction();

foreach (var property in currentObject.Dpo.DpoProperties.Values.Where(property => property.PropertyType == myDefaultValueObject.PropertyType && property.Name == myDefaultValueObject.Name))
{
property.Value = myDefaultValueObject.Value;
}

currentObject.Session.CommitTransaction();
this.View.ObjectSpace.CommitChanges();
base.ObjectSpace.Refresh();
}

Feel free to contact us if you need further assistance or have additional questions.

Regards,
Mariya
On behalf of Xafari Client Services Team

gabossoloClient

Hi Mariya!

I'm using DC (XafariObject) and not PersistentXafariBaseObject.

This code doesn't works: currentObject.Session.CommitTransaction();

Thanks,

Regards,

MariyaVoytovichAgent

Hello gabossolo!

Our apologies for the delay.

Can you send me an example of the code of your object?

Regards,
Mariya
On behalf of Xafari Client Services Team

gabossoloClient

Thanks Mariya!

I have changed my code and it's working now.

public AddDynamicPropertyController()
{
InitializeComponent();

var addDynamicProperty =
new SimpleAction(this, "AddDynamicProperty", PredefinedCategory.RecordEdit)
{
Caption = "AddDynamicProperty"
};
addDynamicProperty.Executed += AddDynamicPropertyOnExecuted;
}

private void AddDynamicPropertyOnExecuted(object sender, ActionBaseEventArgs actionBaseEventArgs)
{
if (!(View.CurrentObject is Currency currentObject)) return;
var propertyName = "myDpo" + currentObject.Dpo.DpoProperties.Count;
var objectSpace = Application.CreateObjectSpace();
var myDefaultValueObject = objectSpace.CreateObject();
myDefaultValueObject.Name = propertyName;
myDefaultValueObject.PropertyType = typeof(DateTime); myDefaultValueObject.ValueDateTime = DateTime.Now;
currentObject.AddProperty(myDefaultValueObject.Name, myDefaultValueObject.PropertyType);

objectSpace.CommitChanges();

//currentObject.Session.CommitTransaction();

foreach (var property in currentObject.Dpo.DpoProperties.Values.Where(property =>
property.PropertyType == myDefaultValueObject.PropertyType &&
property.Name == myDefaultValueObject.Name))
{
property.Value = myDefaultValueObject.Value;
}

objectSpace.CommitChanges();

//currentObject.Session.CommitTransaction();

View.ObjectSpace.CommitChanges();
ObjectSpace.Refresh();
}

× This ticket is closed.

Write US