tags:

views:

8

answers:

0

Hello all,

All I'm trying to do is to inherit from the TriggerBase class and add two dependencies properties. However I'm having a strange issue that I can't use RelativeSource not Path, basically nothing.

Here is the xaml that won't work

public class PropertyTrigger : TriggerBase { private DependencyPropertyDescriptor _propertyDescriptor;

    protected override void OnAttached()
    {
        base.OnAttached();

        if (Property == null)
        {
            return;
        }

        var objectType = AssociatedObject.GetType();
        _propertyDescriptor = DependencyPropertyDescriptor.FromName(Property, objectType, objectType);

        // Do something with the Target if it wasn't null

        _propertyDescriptor.AddValueChanged(AssociatedObject, ValueChanged);            
    }

    protected override void OnDetaching()
    {
        base.OnDetaching();

        if (_propertyDescriptor == null)
        {
            return;
        }

        _propertyDescriptor.RemoveValueChanged(AssociatedObject, ValueChanged);
    }

    private void ValueChanged(object sender, EventArgs args)
    {
        InvokeActions(_propertyDescriptor.GetValue(AssociatedObject));        
    }

    #region Property
    public string Property
    {
        get { return (string)GetValue(PropertyProperty); }
        set { SetValue(PropertyProperty, value); }
    }

    // Using a DependencyProperty as the backing store for Property.  This enables animation, styling, binding, etc...
    public static readonly DependencyProperty PropertyProperty =
        DependencyProperty.Register("Property", typeof(string), typeof(PropertyTrigger), 
        new UIPropertyMetadata(null));
    #endregion

    public object Target
    {
        get { return (object)GetValue(TargetProperty); }
        set { SetValue(TargetProperty, value); }
    }

    public static readonly DependencyProperty TargetProperty =
        DependencyProperty.Register("Target", typeof(object), typeof(PropertyTrigger));

}

No matter what I try it the Target would be null. If I do the following Target="{Binding ElementName=Wnd} that it would work. But once I try to extend it to Target="{Binding ElementName=Wnd, Path=SelectedItems} it stops working again.

I do have a SelectedItems property, as well as I had tryed with all kind of diffrerent properties, the same result.

Any one have any idea? Thank you, Leon