Page 1 of 1

Control states persistency

Posted: 21 Feb 2023, 12:51
by satorp
We're currently looking into a solution to automatically persist (serialize) control states (dependency properties) for dialogs. For example we want some controls on a dialog to resume their states (size, expanded state, ListView's column width etc) when reopening the dialog. The generic requirements are:
  • The solution should provide a way to markup persistable control properties
  • It should be extensible to all dialogs (no specific serialization codes for each dialog)
  • The serialization should be done automatically (e.g. automatic serialize/deserialize on dialog closing/loading)
For WPF, this article on CodeProject offers a very good solution by using markup extensions and automatic generation of persistence Id. The shortcomings are:
  • It uses UIElement.PersisId property which is marked obsolete in WPF
  • It utilizes logical tree path to generate a unique Id, but some control elements may not appear in logical tree (e.g. GridViewColumn)
Since Noesis implementation is not necessarily identical to WPF, I wonder if there's a better way to achieve this in Noesis.

Re: Control states persistency

Posted: 23 Feb 2023, 11:54
by sfernandez
The solution exposed in that article (using a MarkupExtension) looks quite good to me and can be easily implemented in Noesis.

The lack of the PersistId doesn't seem blocking as WPF implemented it just as an auto-increment counter that you can handle in the markup extension itself.

I recommend implementing that approach. If you find any trouble please let us know and we will help.

Re: Control states persistency

Posted: 24 Feb 2023, 16:13
by satorp
@sfernandez Thank you fro the reply.

I have no idea why Microsoft marked PersistId as obsolete. If it's safe and easy to implement then I think it will be nice to have it as part of Noesis framework.

Do you have a suggestion on how to deal with GridViewColumn?

Re: Control states persistency

Posted: 01 Mar 2023, 11:38
by sfernandez
Could you please add the PersistId request to our bugtracker?

For the GridViewColumn you can use Noesis::FindTreeElement() to find the FrameworkElement ancestor holding the column definition.

Re: Control states persistency

Posted: 02 Mar 2023, 14:51
by satorp
I've added this issue to your bugtracker.
We will try your suggestion on GridViewColumn. Thank you.