VS不检测命名空间中的转换函数
本文关键字:转换 函数 命名空间 检测 VS | 更新日期: 2023-09-27 17:54:12
我使用VS2013并构建Windows商店应用程序。解析器未检测species_to_chart_itemsource_converter函数。具体错误:
名称'…命名空间'…'中不存在
我甚至尝试使用clr-namespace:Sustenance_V_1。0,但徒劳。我还尝试在新的。cs文件中定义新的名称空间,但似乎没有任何作用。我已经提到了这个问题:xaml解析器没有检测到我的转换器
请帮助。
PS:我已经在MainPage本身定义了一个类物种,但没有在这里显示。
这是我的mainpage . example .cs文件:
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Runtime.InteropServices.WindowsRuntime;
using Windows.Foundation;
using Windows.Foundation.Collections;
using Windows.UI.Xaml;
using Windows.UI.Xaml.Controls;
using Windows.UI.Xaml.Controls.Primitives;
using Windows.UI.Xaml.Data;
using Windows.UI.Xaml.Input;
using Windows.UI.Xaml.Media;
using Windows.UI.Xaml.Navigation;
using Windows.UI.Xaml.Shapes;
using WinRTXamlToolkit.Controls.DataVisualization.Charting;
// The Blank Page item template is documented at http://go.microsoft.com/fwlink/?LinkId=234238
namespace Sustenance_V_1._0
{
/// <summary>
/// An empty page that can be used on its own or navigated to within a Frame.
/// </summary>
public sealed partial class MainPage : Page
{
//===========Converters==========//
public class species_to_chart_itemsource_converter : IValueConverter
{
public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
{
var sp = parameter as species;
List<Population> data = new List<Population>();
data.Add(new Population() { Name = "Healthy", Amount = sp.healthy });
data.Add(new Population() { Name = "Healthy", Amount = sp.sick });
return data;
}
public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
{
return true;
}
}
public MainPage()
{
this.InitializeComponent();
add_species(all_species);
link_members(all_species);
LoadChartContents(all_species);
}
void MainPage_Loaded(object sender, RoutedEventArgs e)
{
}
}
}
这是主页的顶部。xaml文件:
<Page
xmlns:Charting="using:WinRTXamlToolkit.Controls.DataVisualization.Charting"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="using:Sustenance_V_1._0"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:DataVisualization="using:WinRTXamlToolkit.Controls.DataVisualization" xmlns:Controls="using:WinRTXamlToolkit.Controls" x:Name="page"
xmlns:l="clr-namespace:Sustenance_V_1._0"
x:Class="Sustenance_V_1._0.MainPage"
mc:Ignorable="d">
<Page.Resources>
<Style TargetType="Image">
<Setter Property="Stretch" Value="Uniform"/>
</Style>
<local:species_to_chart_itemsource_converter x:Key="chart_converter"/>
</Page.Resources>
您现在设置的方式,它试图在Sustenance_V_1._0
名称空间中找到species_to_chart_itemsource_converter
,但它不在那里。你把它藏在MainPage
类中。因此,您要么需要用MainPage.species_to_chart_itemsource_converter
作为前缀,要么将转换器移到MainPage
类之外(最好是移到它自己的文件中)。
namespace Sustenance_V_1._0
{
/// <summary>
/// An empty page that can be used on its own or navigated to within a Frame.
/// </summary>
public sealed partial class MainPage : Page
{
public MainPage()
{
this.InitializeComponent();
add_species(all_species);
link_members(all_species);
LoadChartContents(all_species);
}
void MainPage_Loaded(object sender, RoutedEventArgs e)
{
}
}
//This could be in a different file, but I placed it outside the class here just to illustrate.
//===========Converters==========//
public class species_to_chart_itemsource_converter : IValueConverter
{
public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
{
var sp = parameter as species;
List<Population> data = new List<Population>();
data.Add(new Population() { Name = "Healthy", Amount = sp.healthy });
data.Add(new Population() { Name = "Healthy", Amount = sp.sick });
return data;
}
public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
{
return true;
}
}
}