如何绑定ConvertorParameter
我正在尝试绑定 ConverterParameter 的值。目前发现它太棘手了...
代码隐藏
public static readonly DependencyProperty RecognitionProperty = DependencyProperty.Register("RecognitionToEdit", typeof(Recognition), typeof(RecognitionInstancesWindow), null);
public Recognition Recognition
{
get { return (Recognition)GetValue(RecognitionProperty); }
set { SetValue(RecognitionProperty, value); }
}
TextBox 的
<TextBlock HorizontalAlignment="Left" Margin="2,0,0,0" Text="{Binding Converter={StaticResource DateConverter}, Path=Date, ConverterParameter={Binding Recognition, Path=Frequency}}" />
XAML,它构成了 coverflow 类型控件的数据模板的一部分。有人能看出我哪里出错了吗?
I am trying to bind the value of a ConverterParameter. Currently finding it too tricky...
Codebehind
public static readonly DependencyProperty RecognitionProperty = DependencyProperty.Register("RecognitionToEdit", typeof(Recognition), typeof(RecognitionInstancesWindow), null);
public Recognition Recognition
{
get { return (Recognition)GetValue(RecognitionProperty); }
set { SetValue(RecognitionProperty, value); }
}
XAML of a TextBox, which forms part of a datatemplate for a coverflow type control.
<TextBlock HorizontalAlignment="Left" Margin="2,0,0,0" Text="{Binding Converter={StaticResource DateConverter}, Path=Date, ConverterParameter={Binding Recognition, Path=Frequency}}" />
Can anyone see where I'm going wrong please?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
不幸的是,这是不可能的,因为要使属性可绑定,它应该是依赖项,并且该对象应该从 DependencyObject 派生。绑定不是从 DependencyObject 派生的,因此不可能,您应该寻找另一种方法来做到这
一点。一种方法是在静态资源中创建一个类,然后将该类传递给您的转换器,就像这样
从 MyClass 您可以返回任何您想要的东西。想要;)
这个 帖子可能会有所帮助
Unfortunately it is not possible, that's because for property to be bindable it should be dependency, and the object should be derived from DependencyObject. Binding is not derived from DependencyObject, so it is impossible, you should look another ways to do that
One way to do that is to create a class in static resource, and pass that class to your converter like this
from MyClass you can return anything you want ;)
this post can be helpful