anakic/Jot

Jot throwing an exception

SezMe opened this issue · 4 comments

SezMe commented

With this definition of Jot tracking:
Sub New() Trackr.Configure(Of Window)().Id(Function(w) w.Name).Property(Function(w) w.Top).Property(Function(w) w.Left).Property(Function(w) w.Height).Property(Function(w) w.Width).PersistOn(NameOf(Window.Closing)).StopTrackingOn(NameOf(Window.Closing)) End Sub

Jot works fine.

However when I add a new configuration:
Sub New() Trackr.Configure(Of Window)().Id(Function(w) w.Name).Property(Function(w) w.Top).Property(Function(w) w.Left).Property(Function(w) w.Height).Property(Function(w) w.Width).PersistOn(NameOf(Window.Closing)).StopTrackingOn(NameOf(Window.Closing)) Trackr.Configure(Of People)().Id(Function(p) p.Name).Property(Function(p) p.col0.ActualWidth).Property(Function(p) p.col1.ActualWidth).PersistOn(NameOf(People.Closing)).StopTrackingOn(NameOf(People.Closing)) End Sub

Jot throws an error:

Inner Exception 1:
ArgumentException: Expression must be writeable
Parameter name: left

Note that the error occurs on the first configuration NOT on the added configuration!

You must use Width instead of ActualWidth because ActualWidth is a calculated property without a setter. Jot can read it, but it cannot apply previously stored data to it because it hasn't got a set method.

SezMe commented

Yes, I came back to say exactly the same thing. But that creates a different problem. To set the column width, as in my case, the ActualWidth has to be used. Using just Width does not reset the column width when the application restarts.

To show this, use the simple app I've attached. Or just create a wpf window with two columns and include a GridSplitter. Then resize the columns using the GridSplitter, then restart the application. The columns will not be reset to the new sizes
TrackerDemo.zip
.

I see the problem... It's not a problem with Jot, though. If column widths are not initially set to absolute numbers, when the user resizes they are set to relative sizes (with *). For example, if the first column takes 2/3 of the space, the first column will have 2* width and the second one will have 1*. If it's a less tidy fraction, it could end up being e.g. col0.Width=78* and col1.Width=94*. The problem is that you're only tracking the first column so after applying you end up with col0.Width=78* col1.Width=1* (instead of 94*).

The solution is easy, just track the other column as well (give it a name, e.g. col1 and add a call to .Property(Function(p) p.col1.Width).

SezMe commented

Spot on, anakic. Well done. Many thanks for promptly looking into and fixing the issue.