I have attached the InteractionService.Triggers property, which is of type TriggersCollection , which derives from List<ITrigger> . Therefore, I put several trigger objects in XAML, and each of them implements the ITrigger interface. It works fine and was built without any errors. But when I moved this library from Silverlight 5 to Windows Phone 8 and tried to use it with the script described above, Visual Studio 2012 highlighted this XAML with a blue line and reported that there was such an error. When I compile the project, the error disappears from XAML in VS2012 until the next changes to this XAML file. How can I solve this problem? Or is it a VS2012 error with the WP8 SDK? Is there a workaround for this case?
XAML snippet (emphasized by VS2012 + WP8SDK, but not 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 class header:
public class EventTrigger : TriggerBase
TriggerBase class header:
public class TriggerBase : DependencyObject, ITrigger
A fragment of the InteractionService class:
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 }
Error:
A value of type "EventTrigger" cannot be added to a collection or dictionary of type "TriggersCollection".
Another error that is sometimes issued instead:
The value of EventTrigger is not of type ITrigger and cannot be used in this universal collection. Parameter Name: Value