GoogleAnalytics Behavior not droppable on my LayoutRoot

Oct 27, 2010 at 2:23 PM
Edited Oct 27, 2010 at 2:43 PM

I am trying to add GA to my SL4 web site project in Blen 4;  I had no trouble dragging the TrackAction to the frame element.  However, when I try to drag the GoogleAnalytics behavior to my LayoutRoot Blend indicates "Not a valid target".  My workaround is to add a reference to 'Google.Webanalytics' and the following directly into the XAML of the navigation page:

    xmlns:gwa="clr-namespace:Google.WebAnalytics;assembly=Google.WebAnalytics"

...

<ScrollViewer
    x:Name="LayoutRoot"
    HorizontalScrollBarVisibility="Auto"
    VerticalScrollBarVisibility="Auto"
    Padding="0"
    BorderThickness="0">

	<i:Interaction.Behaviors>
        <gwa:GoogleAnalytics WebPropertyId="UA-*********"/>
	</i:Interaction.Behaviors>

...

 

Is this a Blend bug or is there an issue using a ScrollViewer as the LayoutRoot element with Google?

[Edit]

Sorry, I hit the save too soon.

The issue that I ran into after manually adding the Google behavior is that at runtime the GA behavior throws an exception of "Add value to collection of type 'System.Windows.Interactivity.BehaviorCollection' threw an exception. [Line: 26 Position: 44]"

Coordinator
Oct 27, 2010 at 4:12 PM

GoogleAnalytics is a behavior for Panels (because it adds a hidden image) so it must go on Panel-derived class (like Grid or StackPanel).

For you the easiest thing to do is wrap your ScrollViewer in a Grid.

Michael

Oct 27, 2010 at 4:50 PM

Michael,

 

Thanks - That was the issue; You might consider adding a note to that effect on the "Getting started" page of the documentation.  The closest that I found is on the "Architecture" page where it kind of implies that the LayoutRoot is a grid but doesn't really say that any Panel class will do.