2011-07-19 79 views
0


我想谷歌分析整合在我的Silverlight 4出浏览器应用程序。当我在XAML像加我的谷歌Analytics(分析)的代码如下:
使用谷歌Analytics(分析)在Silverlight 4

<i:Interaction.Behaviors> 
     <ga:GoogleAnalytics WebPropertyId="xxxxxxxxxxxxx"/> 
    </i:Interaction.Behaviors> 

我得到一个错误,这是 “增加价值型‘System.Windows.Interactivity.BehaviorCollection’的集合抛出例外。”

的xmlns:I =“HTTP://模式

我无法找到太多的关于这个网帮助,很少在这是我的用户控件的代码中指出。 microsoft.com/expression/2010/interactivity”

目前我使用VS 2010和Blend 4本。
感谢您阅读这一点,如果你能帮助我在这个问题将是巨大的。

编辑:

如前所述,我把数据在这里:

在我的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> 

在主Page.XAML网格下:

<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> 

当我运行这个它给了我一个错误: “添加价值型‘System.Windows.Interactivity.TriggerCollection’的集合引发了异常。”

我失去了一些东西?

回答

0

看来,如果你用完了你,包括你的App.xaml中的东西,像这样的浏览器:

<Application.ApplicationLifetimeObjects><mwa:WebAnalyticsService/></Application.ApplicationLifetimeObjects> 

此外,您运行的是哪个版本?有是固定在版本1.4.7的OOB相关的bug:
http://msaf.codeplex.com/discussions/228657

编辑:我曾在一个小的测试应用程序尝试这样做,现在,它为我工作得很好。它尝试设置谷歌WebPropertyID时会引发异常,但这可能仅仅是因为我自己没有Google Analytics帐户。无论如何,这里是我的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> 

这里是我的参考列表的屏幕截图。 Google.WebAnalytics的引用版本是1.4.6.0,Microsoft.WebAnalytics是1.4.3.0。我安装的框架版本是1.4.10.0,就像你的。我想他们没有用正确的版本号更新所有dll。

enter image description here

编辑2:我只是想你张贴的按钮代码及以下为我工作得很好。我可以看到请求在Fiddler中进入googleanalytics,并且它既可以在浏览器中使用,也可以在浏览器中使用。我添加了对Microsoft.WebAnalytics.Behaviors 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> 
+0

如在邮件中提到我已加入它作为以下<应用 但它示出了作为附加属性 '服务' 未在类型 'WebAnalyticsService' 发现错误。我正在使用最新版本1.4.10 –

+0

感谢您的信息。我在App.xaml文件中添加了信息。现在我试图在Mainpage.xaml中添加Trigger事件,并且出现以下错误:“将值添加到类型'System.Windows.Interactivity.TriggerCollection'的集合中引发了一个异常。” 我已经包含的代码如下: \t \t \t \t \t \t \t \t \t –

+0

如果您编辑原始p ost包含这些代码示例。阅读这篇文章的人更容易阅读和更容易遵循。此外,它看起来像你在EventTrigger中缺少EventName。我猜它应该是“加载”。 –

0

我有完全一样的问题,只有我的项目是的Silverlight 5

很多周围挖原来的项目引用旧版本的Silverlight工具包,具体版本后3

一旦我改变了使用SL5工具包,问题就消失了。

没有解释错误的真正原因,但我希望它有帮助。