【发布时间】:2016-02-02 17:25:27
【问题描述】:
我知道之前有人问过这个问题,但我真的无法根据这些答案弄清楚这里发生了什么,因为以前的提问者似乎将他们的 ivalueconverters 放在不同的类或文件下。我的 IValueConverter 在命名空间 Proc 中,但由于某种原因,我收到了错误:
名称空间中不存在名称“LatValueConverter” “clr 命名空间:过程”。
名称空间中不存在名称“LongValueConverter” “clr 命名空间:过程”。
该代码旨在加载外部文件并根据文件中指定的纬度/经度值放置图像。应用程序构建,但图像不显示,这告诉我此方法失败。 (下面只显示相关代码)
此外,这些错误位于 Visual Studio 错误列表中,但在 xaml 编辑器中键入 local: 后,LatValueConverter 和 LongValueConverter 都会显示在下拉菜单中。我已经尝试清理/重建,但错误仍然出现。有关如何解决此问题的任何想法?
Visual Studio 2015 更新 1 编辑: 我在使用 Visual Studio 2015 Update 1 时注意到这个问题后写了这个问题。我在 Visual Studio 2015 中重新加载了项目(没有更新),没有错误!这似乎是 Visual Studio 2015 Update 1 的一个错误。有人知道解决方法吗?
这里是 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>
这里是 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();
}
}
}
【问题讨论】:
标签: c# .net wpf visual-studio-2015 ivalueconverter