2011-04-09 52 views
1

我創建了一個AttachedProperty,在測試項目中工作得很好,但是在較大的項目中,在一個項目中定義了附加屬性,無法將屬性'X'中的字符串'False'轉換爲'System.Boolean'類型的對象

 
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)); 
在別人我得到這個奇怪的錯誤使用

以前有沒有人遇到過或有過解決方案?

回答

4

謝謝 - 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); 
} 
+0

高興你解決它。 – BoltClock 2011-04-09 05:52:02