I am trying to create an IValueConverter
that takes an enum
and spits out a URI. The converter does work at runtime as expected. However the XAML Designer trows me an error saying:
Object must be the same type as the enum. The type passed in was 'Mocks.WarframeHelper_Model_Enumerations_15_1293735+RelicTypes'; the enum type was 'WarframeHelper.Model.Enumerations+RelicTypes'.
I have a simpler version of my model with the properties I only need at design time but the enum
used is exactly the same (or at least should be). Is there anyway around this.
Here is the code for the IValueConverter
(I am just getting the hang of those things so if I am doing something wrong feel free to correct me)
public class NameToUriConverter : IValueConverter
{
public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
{
if(Enum.IsDefined(typeof(Enumerations.RelicTypes), value))
{
return new Uri("/Assets/RelicIcons/Relic_" + (value).ToString() + ".png", UriKind.Relative);
}
else return new Uri("/Assets/Placeholder.png", UriKind.Relative);
}
public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
{
return value as string;
}
}
and here is the custom data type that I use for the mock data:
public class Sample_RelicModel
{
public Uri ImageUri { get; set; }
public bool isVaulted { get; set; }
public Enumerations.RelicFlavors Flavor { get; set; }
public Enumerations.RelicTypes Type { get; set; }
public Enumerations.DropRearity Rearity { get; set; }
public ObservableCollection<Sample_PrimeItem_Component> DropTable { get; set; }
private int count;
public int Count
{
get { return count; }
set
{
if (value >= 0)
{
count = value;
}
else MessageBox.Show("You don't have enough relics", "Error", MessageBoxButton.OK, MessageBoxImage.Error);
}
}
public Sample_RelicModel() { }
}
Again the converter works as expected at runtime however the XAML designer does not like it because of the mock data.