无法转换字符串“False”在属性“X”中到“System.Boolean”类型的对象
我创建了一个 AttachedProperty ,它在测试项目中工作得很好,但在较大的项目中,其中附加属性在一个项目中定义并在其他项目中使用,我收到这个奇怪的错误:
System.Windows.Markup.XamlParseException occurred Message=Cannot convert string 'False' in attribute 'IsTextDragSource' to object of type 'System.Boolean'. Error at object 'System.Windows.HierarchicalDataTemplate' in markup file 'ServerMonitoringModule;component/view/lists/jobbrowser/jobreportdetailsview.xaml' Line 147 Position 84. Source=PresentationFramework LineNumber=147 LinePosition=84 NameContext=Resources StackTrace: at System.Windows.Markup.XamlParseException.ThrowException(String message, Exception innerException, Int32 lineNumber, Int32 linePosition, Uri baseUri, XamlObjectIds currentXamlObjectIds, XamlObjectIds contextXamlObjectIds, Type objectType) at System.Windows.Markup.XamlParseException.ThrowException(ParserContext parserContext, Int32 lineNumber, Int32 linePosition, String message, Exception innerException) at System.Windows.Markup.XamlTypeMapper.ParseProperty(Object targetObject, Type propType, String propName, Object dpOrPiOrFi, ITypeDescriptorContext typeContext, ParserContext parserContext, String value, Int16 converterTypeId) at System.Windows.Markup.OptimizedTemplateContent.ParseDependencyProperty(String attribValue, Int16 attributeId, Int16 converterTypeId, DependencyProperty& dp, Object& propertyValue) at System.Windows.Markup.OptimizedTemplateContent.LookForShareableRecord(BamlRecord bamlRecord, DependencyProperty& dp, Object& dpValue) at System.Windows.Markup.OptimizedTemplateContent.ReadPotentiallyShareableRecord(BamlRecord bamlRecord) at System.Windows.Markup.OptimizedTemplateContent.ReadRecord(BamlRecord bamlRecord) ...
报告错误的行:
<TextBlock Text="{Binding Text}" dscb:TextDragHelper.IsTextDragSource="False"/>
以及属性的定义:
public class TextDragHelper : DependencyObject
{
public static readonly DependencyProperty IsTextDragSourceProperty =
DependencyProperty.RegisterAttached("IsTextDragSource",
typeof(bool), typeof(TextDragHelper),
new FrameworkPropertyMetadata(OnDragSourceAdvisorChanged));
Did有人以前遇到过这个问题或者有解决方案吗?
I've created an AttachedProperty wich worked just fine in test project but in larger project, where Attached Property is defined in one project and used in others I'm getting this strange error:
System.Windows.Markup.XamlParseException occurred Message=Cannot convert string 'False' in attribute 'IsTextDragSource' to object of type 'System.Boolean'. Error at object 'System.Windows.HierarchicalDataTemplate' in markup file 'ServerMonitoringModule;component/view/lists/jobbrowser/jobreportdetailsview.xaml' Line 147 Position 84. Source=PresentationFramework LineNumber=147 LinePosition=84 NameContext=Resources StackTrace: at System.Windows.Markup.XamlParseException.ThrowException(String message, Exception innerException, Int32 lineNumber, Int32 linePosition, Uri baseUri, XamlObjectIds currentXamlObjectIds, XamlObjectIds contextXamlObjectIds, Type objectType) at System.Windows.Markup.XamlParseException.ThrowException(ParserContext parserContext, Int32 lineNumber, Int32 linePosition, String message, Exception innerException) at System.Windows.Markup.XamlTypeMapper.ParseProperty(Object targetObject, Type propType, String propName, Object dpOrPiOrFi, ITypeDescriptorContext typeContext, ParserContext parserContext, String value, Int16 converterTypeId) at System.Windows.Markup.OptimizedTemplateContent.ParseDependencyProperty(String attribValue, Int16 attributeId, Int16 converterTypeId, DependencyProperty& dp, Object& propertyValue) at System.Windows.Markup.OptimizedTemplateContent.LookForShareableRecord(BamlRecord bamlRecord, DependencyProperty& dp, Object& dpValue) at System.Windows.Markup.OptimizedTemplateContent.ReadPotentiallyShareableRecord(BamlRecord bamlRecord) at System.Windows.Markup.OptimizedTemplateContent.ReadRecord(BamlRecord bamlRecord) ...
Line where error is reported:
<TextBlock Text="{Binding Text}" dscb:TextDragHelper.IsTextDragSource="False"/>
And definition of property:
public class TextDragHelper : DependencyObject
{
public static readonly DependencyProperty IsTextDragSourceProperty =
DependencyProperty.RegisterAttached("IsTextDragSource",
typeof(bool), typeof(TextDragHelper),
new FrameworkPropertyMetadata(OnDragSourceAdvisorChanged));
Did anyone encounter this before or has a solution?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
谢谢 - BoltClock - 你没有回答问题,但我查看了我的源代码,发现我的设置方法是:
虽然这个不知何故在单个项目解决方案中工作,但在多项目解决方案中却不起作用。
这修复了它:
Thanks - BoltClock - you did not answer the question but I've looked at my source and found that my setter method was:
And while this somehow worked in single project solution it did not in multi-project solution.
This fixed it: