2015-06-08 40 views
1

使用VS2013并构建Windows应用商店应用程序。解析器未检测到species_to_chart_itemsource_converter函数。具体错误:VS未检测命名空间中的转换器功能

The name '...' does not exist in namespace '...'

我甚至尝试过使用clr-namespace:Sustenance_V_1._0但徒劳。我也尝试在新的.cs文件中定义新的命名空间,但似乎没有任何工作。我已经提到了这个问题:xaml parser is not detecting my converter

请帮忙。

PS:我已经在MainPage本身定义了一个类的物种,但没有在这里展示它。

这是我MainPage.xaml.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) 
      { 
      } 
     } 
    } 

这是MainPage.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> 
+0

在你的命名空间中有句点是不好的做法。可能不会帮助,但你可能应该将它重命名为'Sustenance_V_1_0'(或者完全删除版本号) – DavidG

+0

@DavidG除非这些时期表示主要功能有所不同。 ('System.Threading' vs'System.Text') –

+0

@DavidG,我也试过。没有帮助。 –

回答

0

您有它设置了现在的样子,它的尝试在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; 
     } 
    } 
} 
+0

我试过了..没有一个为我工作 MainPage ...错误:嵌套不允许 将它放在MainPage类以外不能解决问题。同样的错误 –

+0

你能提供确切的错误吗? “嵌套”错误与原始错误无关。 –

+0

我使用:<本地:MainPage.species_to_chart_itemsource_converter X:键= “chart_converter”/> ,并得到3错误 - 错误\t \t 1嵌套属性不支持:MainPage.species_to_chart_itemsource_converter。 错误在'MainPage'类型中未找到可附加属性'species_to_chart_itemsource_converter'。 \t 错误'解析规则'中的意外'EMPTYPROPERTYELEMENT'NonemptyPropertyElement :: =。 PROPERTYELEMENT内容? ENDTAG。 ''行号“12”和行位置“10”。 –