我创建了一个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));
之前是否有人遇到此问题或有解决方案?
答案 0 :(得分:4)
谢谢 - 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);
}