In one of his blog posts Laurent Bugnion demonstrated the following code snippet as a means of detecting the desingtime mode for wpf
private static bool? _isInDesignMode;
/// <summary>
/// Gets a value indicating whether the control is in design mode (running in Blend
/// or Visual Studio).
/// </summary>
public static bool IsInDesignModeStatic
{
get
{
if (!_isInDesignMode.HasValue)
{
#if SILVERLIGHT
_isInDesignMode = DesignerProperties.IsInDesignTool;
#else
var prop = DesignerProperties.IsInDesignModeProperty;
_isInDesignMode
= (bool)DependencyPropertyDescriptor
.FromProperty(prop, typeof(FrameworkElement))
.Metadata.DefaultValue;
#endif
}
return _isInDesignMode.Value;
}
}
As I happen to work in VB I set about translating this with Telerik's online code converter and ended up with the following:
Private Shared _isInDesignMode As System.Nullable(Of Boolean)
''' <summary>
''' Gets a value indicating whether the control is in design mode (running in Blend
''' or Visual Studio).
''' </summary>
Public Shared ReadOnly Property IsInDesignModeStatic() As Boolean
Get
If Not _isInDesignMode.HasValue Then
#If SILVERLIGHT Then
_isInDesignMode = DesignerProperties.IsInDesignTool
#Else
Dim prop = DesignerProperties.IsInDesignModeProperty
#End If
_isInDesignMode = CBool(DependencyPropertyDescriptor.FromProperty(prop, GetType(FrameworkElement)).Metadata.DefaultValue)
End If
Return _isInDesignMode.Value
End Get
End Property
However if one has Option Strict On on (which I do by default this fails to compile pointing out that there is a discrepancy between the system.windows.DependencyProperty and the system.ComponentModel.DependencyProperty amongst other things.
Most of the errors that code converters throw up I can usually fix in the end but this one (probably because the whole wpf thing is very new to me) is causing me problems.
Could anyone explain the root cause of the error (so that I can actively understand it) and possibly provide a corrected vb conversion.
Thank you