<i:Interaction.Behaviors>
<ga:GoogleAnalytics WebPropertyId="xxxxxxxxxxxxx"/>
</i:Interaction.Behaviors>
I am getting an error which is "Add value to collection of type 'System.Windows.Interactivity.BehaviorCollection' threw an exception."
I am not able to find much of a help in the net regarding this, few pointed out at my user control code which is :
xmlns:i="http://schemas.microsoft.com/expression/2010/interactivity"
currently i am using VS 2010 and Blend 4 for this.
Thanks for reading this and if you are able to help me out in this issue it would be great.EDITED:
As Mentioned I am putting the data here:
In my App.xaml
<Application
x:Class="SilverlightApp.slate.App"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:mwa="clr-namespace:Microsoft.WebAnalytics;assembly=Microsoft.WebAnalytics"
xmlns:ga="clr-namespace:Google.WebAnalytics;assembly=Google.WebAnalytics">
<Application.Resources>
<ResourceDictionary>
<ResourceDictionary.MergedDictionaries>
<ResourceDictionary Source="Assets/Styles.xaml"/>
开发者_开发百科 <ResourceDictionary Source="CustomControls.xaml"/>
</ResourceDictionary.MergedDictionaries>
</ResourceDictionary>
</Application.Resources>
<Application.ApplicationLifetimeObjects>
<mwa:WebAnalyticsService>
<mwa:WebAnalyticsService.Services>
<ga:GoogleAnalytics WebPropertyId="XXXXXXXXXXXXX" />
</mwa:WebAnalyticsService.Services>
</mwa:WebAnalyticsService>
</Application.ApplicationLifetimeObjects>
</Application>
In the Main Page.XAML under the Grid :
<Button x:Name="btn_library_Icon" Margin="86,2,64,6" Style="{StaticResource menu_librarybuttonstyle}" FontFamily="/SilverlightApp.slate;component/Fonts/Fonts.zip#Segoe UI" FontSize="9.333" Click="btn_library_Icon_Click">
<i:Interaction.Triggers>
<i:EventTrigger SourceName="btn_library_Icon" EventName="Click">
<mwab:TrackAction Category="Library Accessed"/>
</i:EventTrigger>
</i:Interaction.Triggers>
<Image x:Name="image" Source="Assets/icon_menu_library.png" Stretch="Fill" Width="23" Height="23"/>
</Button>
when i run this it gives me an error as : "Add value to collection of type 'System.Windows.Interactivity.TriggerCollection' threw an exception."
Am i Missing something here?
It seems that if you are running out of browser you have to include something in your app.xaml, like so:
<Application.ApplicationLifetimeObjects><mwa:WebAnalyticsService/></Application.ApplicationLifetimeObjects>
Also, which version are you running? There was an OOB related bug that was fixed in release 1.4.7:
http://msaf.codeplex.com/discussions/228657
EDIT: I have tried this in a small test app now, and it works fine for me. It throws an exception when trying to set the google WebPropertyID, but that is probably just because I do not have a Google Analytics account myself. Anyway, here is the content of my App.xaml:
<Application xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:mwa="clr-namespace:Microsoft.WebAnalytics;assembly=Microsoft.WebAnalytics"
xmlns:ga="clr-namespace:Google.WebAnalytics;assembly=Google.WebAnalytics"
x:Class="SilverlightApplication22.App">
<Application.ApplicationLifetimeObjects>
<mwa:WebAnalyticsService>
<mwa:WebAnalyticsService.Services>
<ga:GoogleAnalytics WebPropertyId="UA-****-1" />
</mwa:WebAnalyticsService.Services>
</mwa:WebAnalyticsService>
</Application.ApplicationLifetimeObjects>
<Application.Resources>
</Application.Resources>
</Application>
And here is a screen shot from my reference list. The referenced version of Google.WebAnalytics is 1.4.6.0 and Microsoft.WebAnalytics is 1.4.3.0. The version of the framework that I installed is 1.4.10.0, just like yours. I guess they have not updated all dlls with the correct version numbers.
EDIT 2: I just tried the button code you posted and the following works fine for me. I can see the requests going off to googleanalytics in Fiddler, and it works both out of browser and in browser. I have added a reference to Microsoft.WebAnalytics.Behaviors, version 1.4.6.0.
<UserControl x:Class="SilverlightApplication22.MainPage"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:i="clr-namespace:System.Windows.Interactivity;assembly=System.Windows.Interactivity"
xmlns:mwab="clr-namespace:Microsoft.WebAnalytics.Behaviors;assembly=Microsoft.WebAnalytics.Behaviors"
mc:Ignorable="d"
d:DesignHeight="300"
d:DesignWidth="400">
<Grid x:Name="LayoutRoot"
Background="White">
<i:Interaction.Triggers>
<i:EventTrigger SourceName="LayoutRoot"
EventName="Loaded">
<mwab:TrackAction Category="App Loaded" />
</i:EventTrigger>
</i:Interaction.Triggers>
<Button x:Name="Btn01"
Click="Btn01_Click">
<i:Interaction.Triggers>
<i:EventTrigger SourceName="Btn01"
EventName="Click">
<mwab:TrackAction Category="Library Accessed" />
</i:EventTrigger>
</i:Interaction.Triggers>
Test
</Button>
</Grid>
</UserControl>
I had exactly the same issue, only my project was Silverlight 5.
After much digging around it turned out the project was referencing an old version of the Silverlight toolkit, specifically version 3.
Once I changed that to use SL5 toolkit the issue went away.
Doesn't explain the real reason for the error, but I hope it helps anyway.
精彩评论