In design time I have a couple of false errors that seems to be caused by WPF not being able to estimate the value of things without actually running them. This of course works flawlessly in run time.
The question is how do I get rid of these errors?
Here is one example:
I have in a class the following two:
public static bool IsHubb {get; set;}
public static bool IsEC { get { return !IsHubb; } }
The following convertor works perfectly well:
public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
{
if (HubbCostOfferPage.IsHubb && HubbCostOfferPage.CarObj.TestApprovedDate == null)
return Visibility.Visible;
else
return Visibility.Collapsed;
}
The following however (although very similar) gives an “Object reference not set to an instance of an object.” error, which means the only thing I can see on design time without commenting out the StaticResource definition is a big error:
public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
{
if (HubbCostOfferPage.IsEC == true && HubbCostOfferPage.CarObj.TestApprovedDate == null)
return Visibility.Visible;
else
return Visibility.Collapsed;
}
If I replace HubbCostOfferPage.IsEC with HubbCostOfferPage.IsHubb, all works fine so I know that there is where the problem is.
If I replace HubbCostOfferPage.IsEC with !HubbCostOfferPage.IsHubb in the convertor, I get the same problem. The designer seems to complain because it can’t evaluate “!” during design time.
Any ideas how to make this work in design time as well?
Based on Pauls Answer I would suggest not to check is
CarObjis null, because during runtime the exception shall be thrown.I suggest to change your converter as follows: