Current filter:
                                You should refresh the page.
                                  • Hello,

                                    I'm struggling to figure out how to update the text in a static text view item within a detail view in XAF Mobile.

                                    I obtain the view item and have tried the following:
                                    - Set ViewItem.Text
                                    - Set ViewItem.Control("text")
                                    - Set (ViewItem.Control as Label) .Text

                                    None of these yielded any changes to the view and all values were set correctly.

                                    I'm unsure as to what I'm doing wrong. Any help would be greatly appreciated. Thanks!

                                    - Kyle

                                2 Solutions

                                Creation Date Importance Sort by

                                I managed to get it to work by using the event MobilePropertyEditor.ValueStoring instead of ObjectSpace.ObjectChanged. In this event handler, I compare the new value to the current object's value, then set the current object's value if it's different, then set the properties I need, then update the necessary static text items.

                                • Kyle Cohen 08.23.2019

                                  I am having an issue however.

                                  When I have already set one of the properties, specifically the item number, and try to set it again, the other properties of the current object are null. I need these properties in order to perform business logic every time the item number is changed. Those properties have to be specifically set again before they aren't null. Why isn't the current object keeping its values?

                                • Gosha (DevExpress Support) 08.26.2019

                                  Hi Kyle,

                                  As Anatol described in the Mobile Current Object Properties Null ticket, XAF Mobile first restores the current object state from a database and then, applies the client state. Besides, the order in which this state is applied does not depend on the order in which properties were changed. I see that your code depends on properties like FromGPSiteId which does not depend on user input. They are calculated based on other objects and you need to check if a user created these objects in prior. If a user didn't do this, you need to display a message to inform a user about this. In this case, the order in which the state is applied matters.

                                  In this scenario, perform your logic in the MobileWindowTemplate..ViewModelManager.ClientModelRestored event handler. This event is raised when all properties are restored and you can access them in the required order. Handle this event in the OnViewControlsCreated method. In the ClientModelRestored event handler, you can perform your logic in the following way:

                                  [VB.NET]
                                  Private Sub UpdateAll(ByVal sender As Object, ByVal e As EventArgs) SetValuesFromFromBinScan(ThisCurrentObject.FromBin) SetValuesFromToBinScan(ThisCurrentObject.ToBin) ValidateQuantity(ThisCurrentObject.Quantity) UpdateFromLocation(ThisCurrentObject.FromLocation) UpdateToLocation(ThisCurrentObject.ToLocation) SetValuesFromItemNumberScan(ThisCurrentObject.ItemNumber) UpdateItemDescription(ThisCurrentObject.ItemDescription) End Sub

                                  Since the logic implemented in the SetValuesFromItemNumberScan method depends on the logic implemented in the SetValuesFromFromBinScan method, call the SetValuesFromItemNumberScan method after SetValuesFromFromBinScan. But, the logic implemented in the UpdateItemDescription method depends on the SetValuesFromItemNumberScan method's logic. So, call UpdateItemDescription after SetValuesFromItemNumberScan.

                                  This solution also resolves the issue from the XAF Mobile User Friendly Exceptions Not Showing ticket where your exception is wrapped into our InvalidOperation exception.

                                  I've attached a modified project.

                                • Kyle Cohen 08.28.2019

                                  This helped so much! Thank you!

                                  Everything seems to be working as intended.

                                Hi Kyle,

                                XAF Mobile does not have binding between the property and the StaticText Text property. It's necessary to create a custom StaticText View Item to add this binding:

                                [C#]
                                [ViewItem(typeof(IModelStaticText), true)] public class CustomStaticTextViewItem : StaticTextViewItem, IClientModelAware { protected ClientModelManager clientModelManager; public CustomStaticTextViewItem(IModelStaticText model, Type objectType) : base(model, objectType) { } public void Setup(ClientModelManager clientModelManager) { this.clientModelManager = clientModelManager; } protected override object CreateControlCore() { Label label = (Label)base.CreateControlCore(); CalculatedField propertyValue = ClientModelManager.RegisterProperty("Custom" + Id.ToClientIdentifier()); label.Text = ClientModelManager.BindToModel(propertyValue.Name, Text); return label; } public ClientModelManager ClientModelManager { get { return clientModelManager; } } }
                                Show all comments
                                • Kyle Cohen 08.16.2019

                                  Thank you, Gosha.

                                  I'm now a little confused as to how to implement this custom view item.

                                  I created the object in the Module.Mobile project, but I don't see it available in the model.

                                • Gosha (DevExpress Support) 08.16.2019

                                  Hi Kyle,

                                  Apply the ViewItem attribute to this class. It will replace the default StaticTextViewItem. I've modified my code in the answer to illustrate this.

                                • Kyle Cohen 08.19.2019

                                  Hello again Gosha,
                                  Now I'm able to set the text and it stores it, but when I set the text value (which does, indeed, hold the correct value and is set appropriately) the actual client view does not reflect the change to the static text view item; it still shows the old text despite holding the new value.

                                • Gosha (DevExpress Support) 08.20.2019

                                  Hi Kyle,

                                  The following code:

                                  [C#]
                                  Label label = (Label)base.CreateControlCore(); CalculatedField propertyValue = ClientModelManager.RegisterProperty("Custom" + Id.ToClientIdentifier()); label.Text = ClientModelManager.BindToModel(propertyValue.Name, Text);

                                  registers a property named "Custom" plus the Static Text View Item Id you gave in the Model Editor. Then, it binds this property to the Label Text property. So, you can update this property using the ViewModelManager.UpdatePropertyValue method as described in the How to: Implement Client-Side Logic in Mobile Applications article.

                                  [C#]
                                  ViewModelManager viewModelManager = ((MobileWindow)Frame).ViewModelManager; ViewItem item = View.FindItem("MyStaticTextViewItem"); viewModelManager.UpdatePropertyValue("Custom" + item.Id.ToClientIdentifier(), "New Text");
                                • Kyle Cohen 08.20.2019

                                  Thank you Gosha, that solved the issue with updating the static text view items.

                                  The issue now is that when setting certain values, the rest of the fields are null so it can't be updated.
                                  ---
                                  There are 4 fields
                                  - From - Business Object
                                  - Item - String
                                  - Qty - Int
                                  - To - Business Object

                                  When a property is changed and tabbed-off, the application updates some other properties based on some logic and the value entered.

                                  When the From and To are set, the application updates the appropriate properties and static text.

                                  When the Item is set, it works great, but in the on changed method, all of the object's properties are null which causes issues with the other fields, because they're not empty, but the application is acting like it is.

                                  It doesn't do this every time, either. Sometimes some or all of the properties retain their values and it works, but other times only some or all have null values. However, if I save, the values saved are correct. This issue only arises in the current object.

                                  I'm completely confused as to why an instance of an object would sometimes be reset during the on changed method .

                                • Kyle Cohen 08.20.2019

                                  I neglected to say that when the From and To are set, it erases the Item logic that was performed.

                                  The logic sets another few string properties.

                                • Uriah (DevExpress Support) 08.21.2019

                                  Hello Kyle,

                                  We need additional time to answer your question. Please bear with us. We will get back to you as soon as possible.

                                • Gosha (DevExpress Support) 08.22.2019

                                  I appreciate your patience, Kyle. From what I gather, you implemented your business logic in a controller. For example, in the ObjectSpace.ObjectChanged event handler. Since you wrote that your logic is executed once a user focuses another editor, I think your business properties are decorated with the ImmediatePostData attribute. I've prepared a sample project to emulate this logic. Please test it on your side. If your scenario is different, please modify my project to illustrate it. I'll check for an appropriate solution.

                                • Kyle Cohen 08.22.2019

                                  I made some changes to more accurately reflect what I'm trying to accomplish.

                                  I marked changes with "TODO:" comments so they would be easy to find.

                                  One thing I noticed is that when an existing Test object is loaded, the view items are null, even when delayed items initialization is set to false.
                                  ---
                                  To Reproduce:
                                  - Enter a From value
                                  - Enter an Item value containing a 0 or a 1
                                  - Enter a To value

                                  Result:
                                  - At least one static text item is set back to its default when any of the From, Item, or To values are changed.

                                  Expected:
                                  - All static text items reflect their set value.

                                • Kyle Cohen 08.22.2019

                                  On a side note, the Item value doesn't need to have a 0 or 1, but having a 0 or 1 produces a different static text value than not having either; it's probably unnecessary, but it's similar functionality to my application and it works correctly.

                                • Gosha (DevExpress Support) 08.23.2019

                                  Hi Kyle,
                                  Your static view items' Ids are ToLocationStaticTextItem. But, in the OnViewControlsCreated method, you are finding them using ToLocationStaticTextViewItem. That's why the text is lost. In the ObjectSpace.ObjectChanged event handler, you have correct Ids. I've refactored your application to use the same methods in the OnViewControlsCreated method and ObjectSpace.ObjectChanged event handler.

                                • Kyle Cohen 08.23.2019

                                  It appears to be working in the sample solution.

                                  However, the changes did not fix the issue in my solution; some (if not all) values in the current object are null during On Changed. I believe that the view items and other properties are named correctly. The view items are not returning null values.

                                  I attached a copy of my project. Config files are set to localhost and DB named MobileInventoryManagement
                                  To Reproduce:
                                  - Run Application
                                  - Navigate to System Settings
                                        - Set the values as follows: 0, 1, 1, 5
                                  - Navigate to Site Mapping
                                        - Create a new Site Mapping
                                              - Barcode Site Id = "R"
                                              - GP Site Id = Any String
                                              - Company DB Name = Any String
                                  - Navigate to Mobile Inventory Menu
                                  - Click Create New Inventory Transfer
                                  - Enter "R" plus any other 5 characters in From Bin field
                                  - Tab off to next field; static text should update for From Location
                                  - Enter any string in the Item Number field
                                  - Tab off to next field; static text for From Location disappears (it's not supposed to) and static text for Item Description appears
                                  - Enter any value in the Quantity field
                                  - Tab off to next field; an error occurs because current object properties are null - these properties are used to access a database to execute a stored procedure with a return value

                                  The null values can be viewed with a breakpoint at line 143 in InventoryTransferDetailViewController.vb. All of the business logic processes and on changed handlers relevant to this are in that controller.

                                  To summarize, there are two issues:
                                  - Static Text items are disappearing
                                  - Errors occur because current object properties become null

                                  Thanks again, Gosha! I know this is a lot.

                                • Kyle Cohen 08.23.2019

                                  After another quick test, I found that the static text isn't disappearing, but is set to an empty string because the property is seen as empty after the item number is set.