无法转换字符串“False”在属性“X”中到“System.Boolean”类型的对象

发布于 2024-10-31 04:37:57 字数 2299 浏览 0 评论 0原文

我创建了一个 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

落叶缤纷 2024-11-07 04:37:57

谢谢 - BoltClock - 你没有回答问题,但我查看了我的源代码,发现我的设置方法是:

public static void SetIsTextDragSource(DependencyObject source, object value)
{
    source.SetValue(IsTextDragSourceProperty, value);
}

虽然这个不知何故在单个项目解决方案中工作,但在多项目解决方案中却不起作用。

这修复了它:

public static void SetIsTextDragSource(DependencyObject source, bool value)
{
    source.SetValue(IsTextDragSourceProperty, value);
}

Thanks - BoltClock - you did not answer the question but I've looked at my source and found that my setter method was:

public static void SetIsTextDragSource(DependencyObject source, object value)
{
    source.SetValue(IsTextDragSourceProperty, value);
}

And while this somehow worked in single project solution it did not in multi-project solution.

This fixed it:

public static void SetIsTextDragSource(DependencyObject source, bool value)
{
    source.SetValue(IsTextDragSourceProperty, value);
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文