Windows phone 7 错误:类型为';System.Windows.Markup.XamlParseException';发生在System.Windows.ni.dll中
我有windows phone应用程序;当我运行应用程序时,我得到了这个异常,它不再运行了Windows phone 7 错误:类型为';System.Windows.Markup.XamlParseException';发生在System.Windows.ni.dll中,windows-phone-7,windows-phone-8,Windows Phone 7,Windows Phone 8,我有windows phone应用程序;当我运行应用程序时,我得到了这个异常,它不再运行了 A first chance exception of type 'System.Windows.Markup.XamlParseException' occurred in System.Windows.ni.dll InitializeComponent()中的app.xaml文件中出现错误;方法 因为在添加应用程序资源时发生了错误 <converter:RssTextTrimmer xm
A first chance exception of type 'System.Windows.Markup.XamlParseException' occurred in System.Windows.ni.dll
InitializeComponent()中的app.xaml文件中出现错误;方法
因为在添加应用程序资源时发生了错误
<converter:RssTextTrimmer xmlns:converter="clr-namespace:HomePage" x:Key="RssTextTrimmer" />
当我删除它时,应用程序运行良好
以下是完整的代码:
<Application
x:Class="HomePage.App"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:phone="clr-namespace:Microsoft.Phone.Controls;assembly=Microsoft.Phone"
xmlns:shell="clr-namespace:Microsoft.Phone.Shell;assembly=Microsoft.Phone">
<!--Application Resources-->
<Application.Resources>
<local:LocalizedStrings xmlns:local="clr-namespace:HomePage" x:Key="LocalizedStrings"/>
<converter:RssTextTrimmer xmlns:converter="clr-namespace:HomePage" x:Key="RssTextTrimmer" />
</Application.Resources>
<Application.ApplicationLifetimeObjects>
<!--Required object that handles lifetime events for the application-->
<shell:PhoneApplicationService
Launching="Application_Launching" Closing="Application_Closing"
Activated="Application_Activated" Deactivated="Application_Deactivated"/>
</Application.ApplicationLifetimeObjects>
转换器代码
命名空间主页
{
RssTextTrimmer类:IValueConverter
{
//清除每个联合项目中的文本字段。
公共对象转换(对象值、类型targetType、对象参数、CultureInfo区域性)
{
if(value==null)返回null;
int maxLength=200;
int strLength=0;
字符串fixedString=“”;
//从文本中删除HTML标记和换行符,并解码HTML编码字符。
//这是一个基本的方法。需要额外的代码才能更彻底地使用它
//删除某些元素,例如嵌入式Javascript。
//删除HTML标记。
fixedString=Regex.Replace(value.ToString(),“]+>”,string.Empty);
//删除换行符
fixedString=fixedString.Replace(“\r”,”).Replace(“\n”,”);
//删除编码的HTML字符
fixedString=HttpUtility.HtmlDecode(fixedString);
strLength=fixedString.ToString().Length;
//一些提要管理工具在RSS提要的描述字段中包含图像标记,
//因此,即使没有填充Description字段(以及Summary属性),它仍然可能包含HTML。
//因此,在从字符串中去掉标记后,如果结果字符串中没有任何内容,则应返回null。
如果(strLength==0)
{
返回null;
}
//如果文本太长,请将其截断。
else if(strLength>=maxLength)
{
fixedString=fixedString.Substring(0,maxLength);
除非我们采取下一步,否则字符串截断可能发生在单词的中间。
//使用LastIndexOf可以找到字符串中的最后一个空格字符并在那里截断。
fixedString=fixedString.Substring(0,fixedString.LastIndexOf(“”);
}
fixedString+=“…”;
返回固定字符串;
}
//这个代码示例不使用双向绑定,因此,我们不需要充实ConvertBack。
公共对象转换回(对象值、类型targetType、对象参数、CultureInfo区域性)
{
抛出新的NotImplementedException();
}
}
}在RssTextTrimmer.cs文件中,确保该类是公共的 “公共类RssTextTrimmer:IValueConverter” 不 “RssTextTrimmer类:IValueConverter”
这就是buggered mine up的内容显示XAML代码,因为它是一个XamlParseException,错误应该在那里。显示您的转换器code@AlaaMasoud更新。完美答案,无法创建实例,因为默认情况下它是受保护的,所以将其公开将起作用,感谢战利品
<Application
x:Class="HomePage.App"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:phone="clr-namespace:Microsoft.Phone.Controls;assembly=Microsoft.Phone"
xmlns:shell="clr-namespace:Microsoft.Phone.Shell;assembly=Microsoft.Phone">
<!--Application Resources-->
<Application.Resources>
<local:LocalizedStrings xmlns:local="clr-namespace:HomePage" x:Key="LocalizedStrings"/>
<converter:RssTextTrimmer xmlns:converter="clr-namespace:HomePage" x:Key="RssTextTrimmer" />
</Application.Resources>
<Application.ApplicationLifetimeObjects>
<!--Required object that handles lifetime events for the application-->
<shell:PhoneApplicationService
Launching="Application_Launching" Closing="Application_Closing"
Activated="Application_Activated" Deactivated="Application_Deactivated"/>
</Application.ApplicationLifetimeObjects>
// Clean up text fields from each SyndicationItem.
public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
{
if (value == null) return null;
int maxLength = 200;
int strLength = 0;
string fixedString = "";
// Remove HTML tags and newline characters from the text, and decodes HTML encoded characters.
// This is a basic method. Additional code would be needed to more thoroughly
// remove certain elements, such as embedded Javascript.
// Remove HTML tags.
fixedString = Regex.Replace(value.ToString(), "<[^>]+>", string.Empty);
// Remove newline characters
fixedString = fixedString.Replace("\r", "").Replace("\n", "");
// Remove encoded HTML characters
fixedString = HttpUtility.HtmlDecode(fixedString);
strLength = fixedString.ToString().Length;
// Some feed management tools include an image tag in the Description field of an RSS feed,
// so even if the Description field (and thus, the Summary property) is not populated, it could still contain HTML.
// Due to this, after we strip tags from the string, we should return null if there is nothing left in the resulting string.
if (strLength == 0)
{
return null;
}
// Truncate the text if it is too long.
else if (strLength >= maxLength)
{
fixedString = fixedString.Substring(0, maxLength);
// Unless we take the next step, the string truncation could occur in the middle of a word.
// Using LastIndexOf we can find the last space character in the string and truncate there.
fixedString = fixedString.Substring(0, fixedString.LastIndexOf(" "));
}
fixedString += "...";
return fixedString;
}
// This code sample does not use TwoWay binding and thus, we do not need to flesh out ConvertBack.
public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
{
throw new NotImplementedException();
}
}