Search code examples
c#.netwpfvisual-studio-2015ivalueconverter

xaml is not seeing my ivalueconverter


I know this has been asked before, but I really can't figure out what's going on here based on these answers, because it seems previous askers had placed their ivalueconverters under different classes or files. My IValueConverter is in the namespace Proc, but for some reason, I am getting the errors:

The name "LatValueConverter" does not exist in the namespace "clr-namespace:Proc".

The name "LongValueConverter" does not exist in the namespace "clr-namespace:Proc".

The code is meant to load an external file and place images according to the lat/lon values specified in the file. The application builds, but the images do not show up, which tells me that this method fails. (only showing relevant code below)

Furthermore, these errors are in the visual studio errors list, but both LatValueConverter and LongValueConverter show up in the drop down menu after typing local: in the xaml editor. I have tried cleaning/rebuilding but the errors still show up. Any thoughts on how to fix this?

Visual Studio 2015 Update 1 EDIT: I wrote this question after noticing it while using Visual Studio 2015 Update 1. I re-loaded the project in Visual Studio 2015 (no update), and no errors! This seems to be a bug with Visual Studio 2015 Update 1. Any one know of a work around?

Here is the xaml:

<Window x:Class="Proc.MainWindow"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
    xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
    xmlns:sys="clr-namespace:System;assembly=mscorlib"
    xmlns:local="clr-namespace:Proc"
    mc:Ignorable="d">
<Window.Resources>
    <ResourceDictionary>
        <local:LatValueConverter x:Key="latValueConverter" /> <!-- Errors are here -->
        <local:LongValueConverter x:Key="longValueConverter" /> <!-- Errors are here -->
        <sys:Double x:Key="mapWidth">950</sys:Double>
        <sys:Double x:Key="mapHeight">530</sys:Double>
    </ResourceDictionary>
</Window.Resources>

Here is MainWindow.xaml.cs:

namespace Proc
{
    public partial class MainWindow : Window, INotifyPropertyChanged
    {
      //...
    }
    public class LatValueConverter : IValueConverter
    {
        public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
        {
            double latitude = (double)value;
            double height = (double)parameter;

            int top = (int)((Constants.LatTop - latitude) / (Constants.LatTop - Constants.LatBottom) * height);
            return top;
        }

        public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
        {
            throw new NotImplementedException();
        }
    }

    public class LongValueConverter : IValueConverter
    {
        public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
        {
            double longitude = (double)value;
            double width = (double)parameter;

            int left = (int)((Constants.LongLeft - longitude) / (Constants.LongLeft - Constants.LongRight) * width);
            return left;
        }

        public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
        {
            throw new NotImplementedException();
        }
    }
}

Solution

  • I've had the same problem on VS 2015 Update 1.

    The code builds and runs ok, but the Designer complains that "some elements haven't been built yet..." and if I hover with the mouse on the "offending" part of the XAML the tooltip shows "MyCustomConverter does not exist in the namespace etc..."

    For some reason, in my case, I get this designer behaviour only if I build the solution as ANY CPU. If I force it to x64 then the designer works.

    I haven't tried VS 2015 update 2 yet.