views:

383

answers:

1

I am using Expresion Blend 3 and created a new user control in my project. I want a storyboard to run if a custom property of that user control is triggered like with the ones shown here in the list..

alt text

I learnt you need a dependency property, but my understanding there is limited. Here's the basic code I set up with property "IsAwesome" as an example..

Partial Public Class simpleControl
    Public Sub New()
     MyBase.New()
        Me.InitializeComponent()
    End Sub

    Public Shared ReadOnly IsAwesomeProperty As DependencyProperty = _
        DependencyProperty.Register("IsAwesome", GetType(Boolean), GetType(simpleControl))

    Public Property IsAwesome() As Boolean
        Get
            Return DirectCast(Me.GetValue(IsAwesomeProperty), Boolean)
        End Get
        Set(ByVal value As Boolean)
            Me.SetValue(IsAwesomeProperty, value)
        End Set
    End Property
End Class

However, my property doesn't show in that list. What am I missing? Or is my entire approach wrong? Any help or advice would be appreciated!

Cheers

+1  A: 

I created a new Wpf project. Added a new UserControl (UserControl1) with a custom dependency property called Foo.

Then I opened Blend and added an instance of UserControl1 to Window1. I right clicked on UserControl1 and said EditTemplate | Edit a Copy.

This created a copy of my user control template in the Window.Resources. From within this new template I went up to the Triggers panel and clicked the button to add a new property trigger.

Right away Blend defaulted to selecting my property in the "Activated When" section.

alt text

You can grab my little sample app from here: http://blog.BradCunningham.net/SourceCode/ForumSamples/CustomDPInBlend.zip

Foovanadil
Wow! Much appreciated! I guess I was editing templates from the wrong place then. However, is there a way I could alter controls inside the usercontrol from this? eg making visible a textblock saying "This control is empty" if property .IsEmpty is true.
jay
Sure, In the screen shot I posted I am inside the ControlTemplate for UserControl1. The Trigger I am setting is activated when Foo = null.As you can see, Blend is showing me (via the red outline) that Foo = null trigger recording is on. This means any properties I change on my visual elements will only be set when the trriger is activated (when Foo = null). If you flip back to Default (i.e. Deactive the Foo = null trigger) you will notice the properties you set inside the Foo trigger are undone.
Foovanadil
But I still can't edit controls inside the UserControl via template editing can I? http://i49.tinypic.com/10wo5q9.png - since they're not available in the Objects list. I guess that can just be done by code then. Thanks, again.
jay