我附加了属性InteractionService.Triggers
,其类型为TriggersCollection
,派生自List<ITrigger>
。所以我在XAML中添加了一些触发器对象,并且每个触发器对象都实现了接口ITrigger
。它工作正常,并且没有任何错误地构建。但是当我将这个库从Silverlight 5移植到Windows Phone 8并尝试将其与上述场景一起使用时,Visual Studio 2012用蓝线强调了这个XAML并告诉它存在这样的错误。当我编译项目时,错误从VS2012中的XAML消失,直到在此XAML文件中进行下一次编辑。
我该如何解决这个问题?或者这是VS2012与WP8 SDK的错误?这种情况有解决办法吗?
XAML的片段(由VS2012 + WP8SDK加下划线,但不是由VS2010 + SL5加下划线):
<deToolkit:InteractionService.Triggers>
<deToolkit:EventTrigger EnterEvent="Loaded">
<deToolkit:CommandSetter Command="{Binding LoadCommand}" />
</deToolkit:EventTrigger>
</deToolkit:InteractionService.Triggers>
TriggersCollection:
public class TriggersCollection : List<ITrigger> { }
EventTrigger类的标题:
public class EventTrigger : TriggerBase
TriggerBase类的标题:
public class TriggerBase : DependencyObject, ITrigger
类InteractionService的片段:
public sealed class InteractionService : DependencyObject
{
#region [ADP] Triggers : TriggersCollection (Triggers applied to control)
public static void SetTriggers(DependencyObject element, TriggersCollection value)
{
element.SetValue(TriggersProperty, value);
}
public static TriggersCollection GetTriggers(DependencyObject element)
{
var triggers = (TriggersCollection)element.GetValue(TriggersProperty);
if (triggers == null)
{
var collection = new TriggersCollection();
if (!DesignerProperties.IsInDesignTool)
{
// -- some code --
}
SetTriggers(element, collection);
return collection;
}
return triggers;
}
public static readonly DependencyProperty TriggersProperty =
DependencyProperty.RegisterAttached("Triggers", typeof(TriggersCollection), typeof(InteractionService), null);
#endregion Triggers
}
错误:
“EventTrigger”类型的值无法添加到“TriggersCollection”类型的集合或字典中。
有时会抛出另一个错误:
值“EventTrigger”不是“ITrigger”类型,不能在此通用集合中使用。参数名称:值