![](/img/trans.png)
[英]Expression of type 'System.Func`2[T,System.Boolean]' cannot be used for return type 'System.Boolean'
[英]Cannot convert string 'False' in attribute 'X' to object of type 'System.Boolean'
我已經創建了一個在測試項目中工作得很好的AttachedProperty,但是在更大的項目中,Attached Property在一個項目中定義並在其他項目中使用我得到了這個奇怪的錯誤:
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));
有沒有人遇到這個或有解決方案?
謝謝 - 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);
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.