Silverlight 3 - 通过 XAML 将绑定值传递给行为
我创建了一个自定义行为,我可以将属性传递给精细的当前只是字符串,我的行为大致如下所示:
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);
}.............
}
我可以将它与标准字符串一起使用,如下所示:
<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>
我的问题是,如何传递绑定值而不是只是一个字符串,如下所示:
<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>
当我尝试此操作时,即使绑定有效,我也只是收到 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">
<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
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论