Property Trigger on UserControl not available RRS feed

  • Question

  • Let me first start off by saying that I am trying to learn a little about WPF coming from a WinForms and WebForm development.

    I created a user control in WPF called: AlertImage.xaml

    I then created a user-defined property using the following code:

        Private _alert_type As AlertTypes = AlertTypes.None  
        Enum AlertTypes  
        End Enum 
        <Category("Common Properties")> _  
        Public Property AlertType() As AlertTypes  
                Return _alert_type  
            End Get 
            Set(ByVal value As AlertTypes)  
                _alert_type = value  
            End Set 
        End Property 

    I now want to create an animation based on this property.  (i.e.  start animation when this property is changed to a certain value)

    So, after reading and learned that I needed to make this property a "Dependency Property" so I added the following line:
        Public Shared ReadOnly AlertTypeProperty As DependencyProperty = _  
                               DependencyProperty.Register("AlertType"GetType(AlertTypes), GetType(AlertImage)) 

    The problem is, when I go to Expression Blend, the Property Trigger is disabled and will not let me add a animation based on the property changing...

    Can anyone explain how to do this to a newbie?  Sorry for the lack of understanding.  Also, any books or references to use to try to learn the basics quicker?

    Thanks in advanced
    Saturday, June 14, 2008 4:15 AM


  • Hi,

    Property triggers are supported only within Styles (See http://msdn.microsoft.com/en-us/library/system.windows.trigger.aspx)

    I can suggest 2 solutions.

    1. Edit a copy of the Style for your control. Then you can set a property trigger for the custom property exposed on the control.

    2. Add a custom event for the change in value for you custom property. You can then fire the event whenever the property is set to a particular value (or as per your requirement)
    You can then use the Event Triggers to trigger the animation you want.

    Jeetendra Kukreja [MSFT]
    Sunday, June 15, 2008 9:57 PM