Silverlight 3 - Passing a binding value to a behavior through XAML
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">
开发者_JAVA百科 <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
精彩评论