/// <summary>
        /// Called after the trigger is attached to an AssociatedObject.
        /// </summary>
        protected override void OnAttached()
        {
            base.OnAttached();

            this.visualStateChanged = this.Source.DataContext as INotifyVisualStateChanged;

            // TODO: Walk up the visual tree to potentially find a parent INotifyVisualStateChanged
            if (this.visualStateChanged == null)
            {
                throw new ArgumentException("Cannot attach to FramworkElement without VisualStateChanged as DataContext.");
            }

            this.visualStateChanged.VisualStateChanged += this.OnVisualStateChanged;
        }
Example #2
0
        protected override void OnAttached()
        {
            base.OnAttached();

            // Find provider
            if (AssociatedObject.Parent != null)
            {
                stateProvider = FindParentStateProvider(AssociatedObject.Parent);

                // If found, subscribe to events
                if (stateProvider != null)
                {
                    stateProvider.VisualStateChanged += StateProvider_VisualStateChanged;
                }
            }
        }
        protected override void OnAttached()
        {
            base.OnAttached();

            // Find provider
            if (AssociatedObject.Parent != null)
            {
                stateProvider = FindParentStateProvider(AssociatedObject.Parent);

                // If found, subscribe to events
                if (stateProvider != null)
                {
                    stateProvider.VisualStateChanged += StateProvider_VisualStateChanged;
                }
            }
        }