2011-07-19 120 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工具包,問題就消失了。

沒有解釋錯誤的真正原因,但我希望它有幫助。