views:

327

answers:

1

Hi,

I have created a custom behavior that I can pass properties to fine, currently just strings, my behavior looks roughly like this:

    public class ImageSourceBehavior : Behavior<Image>, INotifyPropertyChanged
{
    public static readonly DependencyProperty ImageDirectoryProperty = DependencyProperty.Register("ImageDirectory", typeof(string), typeof(ImageSourceBehavior), new PropertyMetadata(null));
    public string ImageDirectory
    {
        get
        {
            return (string)GetValue(ImageDirectoryProperty);
        }
        set
        {
            SetValue(ImageDirectoryProperty, value);
        }
    }

    public static readonly DependencyProperty ImageExtensionProperty = DependencyProperty.Register("ImageExtension", typeof(string), typeof(ImageSourceBehavior), new PropertyMetadata(null));
    public string ImageExtension
    {
        get
        {
            return (string)GetValue(ImageExtensionProperty);
        }
        set
        {
            SetValue(ImageExtensionProperty, value);
        }.............
    }

I can use it fine with standard strings like so:

               <Image x:Name="flag" Stretch="Uniform"  MaxWidth="150" MaxHeight="150">
                                                        <i:Interaction.Behaviors>
                                                            <infrastructure:ImageSourceBehavior ImageDirectory="/Theme_External;component/Media/Images/Flags/" ImageExtension=".png" ImageNameWithoutExtension="some test text" />
                                                        </i:Interaction.Behaviors>
                                                    </Image>

My question is, how do I pass in a binding value instead of just a string, like this:

               <Image x:Name="flag" Stretch="Uniform"  MaxWidth="150" MaxHeight="150">
                                                        <i:Interaction.Behaviors>
                                                            <infrastructure:ImageSourceBehavior ImageDirectory="/Theme_External;component/Media/Images/Flags/" ImageExtension=".png" ImageNameWithoutExtension="{Binding Path=.}" />
                                                        </i:Interaction.Behaviors>
                                                    </Image>

I just get a XAML parse exception when I try this, even though the binding is valid, any ideas?

Thanks for your time

+1  A: 

Found this reply which will hopefully resolve the issue:

http://stackoverflow.com/questions/1486861/error-when-binding-a-dependency-property-on-a-custom-behavior

JimmySavile