Referencing shared properties within computed property resetting to default values on canvas subclas

I have a canvas subclass (CanvScheduleViewer) with a few shared properties. These are accessed via (non-shared) computed properties to allow default values and some necessary calculations.

Seems whenever I open a new window with one of these canvas subclasses in it, the non-shared computed property will be set to the defaults (such as 0 for integers, and false for booleans) and that will set the shared properties to the same values.

I don’t think I can change the non-shared computer properties to shared computer properties since they use values based on the current instance for some calculations.

A quick example is I have a widthPerDay local computed integer:

[code]Public Property widthPerDay as Integer
Get
if CanvScheduleViewer.mWidthPerDay = 0 then
//default
CanvScheduleViewer.mWidthPerDay = 110
end if

if autoResizeDayWidths then
Return (me.Width-BorderLeft - BorderRight) / daysToShow
else
Return CanvScheduleViewer.mWidthPerDay
end if
End Get

Set
CanvScheduleViewer.mWidthPerDay = value
End Set

End Property
[/code]

Here’s the shared integer it’s referencing:

Public Shared Property mWidthPerDay as Integer

However whenever a CanvScheduleViewer is created, it will set widthPerDay = 0, which sets CanvScheduleViewer.mWidthPerDay to zero.

I’ve got a temporary workaround by making sure in the Set command to prevent the value from being set if it’s zero/blankstring, etc. But obviously this isn’t optimal because you can’t use zero as a value and it won’t work for booleans.

Why do you need a setter if you do not do anything instance related in it? Just delete the code and the setter will not be called.

Also you should not set the default value of a shared property in an instance property – they have nothing to do with each other. Use lazy initialization for the shared property on the “shared” level:

[code]Private Shared mStandardWidthPerDay As Integer

Public Shared Property StandardWidthPerDay As Integer
Get
If mStandardWidthPerDay = 0 Then
mStandardWidthPerDay = 110
End
Return mStandardWidthPerDay
End
Set
mStandardWidthPerDay = value
End
End Property[/code]

The whole setup does not make a lot of sense to me, it seems to be over-complicating things. If you do not set StandardWidthPerDay from anywhere (like a preferences dialog or so), you should go for a constant.