【问题标题】:Cannot convert string 'False' in attribute 'X' to object of type 'System.Boolean'无法将属性“X”中的字符串“False”转换为“System.Boolean”类型的对象
【发布时间】:2011-04-09 05:14:17
【问题描述】:

我创建了一个 AttachedProperty,它在测试项目中工作得很好,但在更大的项目中,附加属性在一个项目中定义并在其他项目中使用我得到这个奇怪的错误:

System.Windows.Markup.XamlParseException 发生 消息=无法在属性“IsTextDragSource”中转换字符串“False” 到“System.Boolean”类型的对象。 标记文件中的对象“System.Windows.HierarchicalDataTemplate”出错 'ServerMonitoringModule; 组件/视图/列表/jobbrowser/jobreportdetailsview.xaml' 第 147 行位置 84。Source=PresentationFramework LineNumber=147 LinePosition=84 NameContext=资源 堆栈跟踪: 在 System.Windows.Markup.XamlParseException.ThrowException(字符串消息,异常 innerException,Int32 lineNumber,Int32 linePosition,Uri baseUri,XamlObjectIds currentXamlObjectIds,XamlObjectIds contextXamlObjectIds,类型 objectType) 在 System.Windows.Markup.XamlParseException.ThrowException(ParserContext parserContext,Int32 lineNumber,Int32 linePosition,字符串消息,异常 innerException) 在 System.Windows.Markup.XamlTypeMapper.ParseProperty(对象 targetObject,类型 propType,字符串 propName,对象 dpOrPiOrFi,ITypeDescriptorContext typeContext,ParserContext parserContext,字符串值,Int16 converterTypeId) 在 System.Windows.Markup.OptimizedTemplateContent.ParseDependencyProperty(字符串 attribValue,Int16 attributeId,Int16 converterTypeId,DependencyProperty&dp,Object&propertyValue) 在 System.Windows.Markup.OptimizedTemplateContent.LookForShareableRecord(BamlRecord bamlRecord,DependencyProperty& dp,Object& dpValue) 在 System.Windows.Markup.OptimizedTemplateContent.ReadPotentiallyShareableRecord(BamlRecord bamlRecord) 在 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));

有没有人遇到过这种情况或有解决办法?

【问题讨论】:

    标签: c# wpf xaml attached-properties


    【解决方案1】:

    谢谢 - BoltClock - 你没有回答这个问题,但我查看了我的来源,发现我的 setter 方法是:

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

    虽然这个以某种方式在单项目解决方案中起作用,但在多项目解决方案中却没有。

    这解决了它:

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

    【讨论】:

      猜你喜欢
      • 2020-08-07
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-09-08
      • 2017-12-30
      • 2010-10-05
      • 1970-01-01
      相关资源
      最近更新 更多