InteractionBehaviors

Feb 23, 2012 at 8:16 PM

Does snoop currently support interaction behaviors and if not are there plans to add this functionality?

Coordinator
Feb 23, 2012 at 8:37 PM

What exactly do you mean by interaction behaviors?

Feb 24, 2012 at 12:10 AM
Edited Feb 24, 2012 at 12:13 AM

System.Windows.Interactivity.Behavior(of T)

The wpf system uses attached properties freezable collection attached property to add these behaviors.

Example Markup:


 <UserControl x:Class="SomeControNamel"

xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"             

xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"             

xmlns:col="clr-namespace:System.Collections;assembly=mscorlib"       

xmlns:v="clr-namespace:SomeNamespace.View"    

 xmlns:i="clr-namespace:System.Windows.Interactivity;assembly=System.Windows.Interactivity">

<SomeControl>

<i:Interaction.Behaviors>

<v:SomeBehavior />

<v:SomeOtherBehavior SomeProperty="{Binding RelativeSource={RelativeSource Mode=FindAncestor, AncestorType={x:Type SomeControl}}, Path=DataContext.SomeBinding}" />

</i:Interaction.Behaviors

</SomeControl>


</UserControl> 

 

I can't find data for these behaviors.

Coordinator
Feb 24, 2012 at 5:51 PM

Are you saying that with Snoop ... you can't see these attached properties?

I just tried to find the Interaction.Behaviors attached property ... using Snoop ... and it wasn't able to see it ... which is odd since you can see other attached properties. I tried using Mole too ... and it wasn't able to see them either.

What is weird ... is that Snoop can see custom attached properties just fine ... so I'm not sure why Snoop can't see Interaction.Behaviors.

This is something to dive on it.

Can you confirm with me ... that this is indeed what you are trying to do?

Feb 24, 2012 at 7:36 PM
Edited Feb 27, 2012 at 6:03 PM

 

You are correct.  I also did some research on another attached property that I made that is built a lot like the interaction behaviors and was unable to see that property as well.  I believe the issue is Attached Property is a friend and the property string name is different than the property name.  I use this technique to bind across visual trees without the need for a spy.  I also use it for event command mapping collections.

Example of this type of Attached Property


   Public Class AttachedCollectionClass

#Region "SomeFreezableCollectionAttachedProperty"

' Make it Friend so WPF ignores the property and always uses the        

'public getter/setter. This is per John Gossman blog post - 07/2008.        

Friend Shared ReadOnly SomeFreezableCollectionAttachedProperty As DependencyProperty =           

 DependencyProperty.RegisterAttached("InternalMappings",                                               

 GetType(SomeCustomFreezableCollection),                                               

 GetType(AttachedCollectionClass),                                               

New UIPropertyMetadata(Nothing, AddressOf OnMappingsChanged))

Friend Shared Function InternalGetMappingCollection(ByVal obj As DependencyObject) As SomeCustomFreezableCollection

Dim map = TryCast(obj.GetValue(SomeFreezableCollectionAttachedProperty), SomeCustomFreezableCollection)           

If map Is Nothing Then               

map = New BindingBridgeCollection()               

SetMappings(obj, map)           

End If           

 

Return map       

End Function

Public Shared Function GetSomeFreezableCollectionAttached(ByVal obj As DependencyObject) As SomeCustomFreezableCollection

Return InternalGetSomeFreezableCollectionAttachedCollection(obj)       

End Function

 

 Public Shared Sub SetSomeFreezableCollectionAttached(ByVal obj As DependencyObject, ByVal value As SomeCustomFreezableCollection)            obj.SetValue(MappingsProperty, value)       

End Sub

  Private Shared Sub OnMappingsChanged(ByVal target As DependencyObject, ByVal e As DependencyPropertyChangedEventArgs)           

Dim cec As SomeCustomFreezableCollection= TryCast(e.NewValue, SomeCustomFreezableCollection)
            If cec Is Nothing Then               

Return           

End If           

Dim _Element As ContentControl = TryCast(target, ContentControl)           

If _Element Is Nothing Then               

Return           

End If           

For Each item In cec               

item.Content= _Element           

Next
        End Sub

#End Region

End Class

Public Class SomeCustomFreezableCollection

Inherits FreezableCollection(of ContentControl)

End Class 

Feb 27, 2012 at 11:36 PM

Would you like me to enter a more general thread referencing this under issue tracker?  I ask for your convenience as I don't know how you like to organize your issues.  

Coordinator
Feb 28, 2012 at 7:24 PM
This discussion has been copied to a work item. Click here to go to the work item and continue the discussion.
Coordinator
Feb 28, 2012 at 7:34 PM

Thanks ... I just copied this discussion to a work item: http://snoopwpf.codeplex.com/workitem/7769

To make it easy on us ... as we go to repro and work on this ... if you could attach a small test harness ... with a custom attached property like what you are discussing above ... and attach it to the issue in the Issue Tracker ... that would be awesome and helpful.

Feb 28, 2012 at 7:42 PM

NP... Will attach a quick example as soon as I can get a few free minutes to set one up.

Feb 29, 2012 at 8:15 PM

http://snoopwpf.codeplex.com/workitem/7769 seems to be locked right now.  I have a project ready to upload.