如何绑定ConvertorParameter

发布于 2024-09-29 20:01:31 字数 730 浏览 6 评论 0原文

我正在尝试绑定 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

水水月牙 2024-10-06 20:01:32

不幸的是,这是不可能的,因为要使属性可绑定,它应该是依赖项,并且该对象应该从 DependencyObject 派生。绑定不是从 DependencyObject 派生的,因此不可能,您应该寻找另一种方法来做到这

一点。一种方法是在静态资源中创建一个类,然后将该类传递给您的转换器,就像这样

<namespace:MyClass x:Key="MyClass">

<Binding ... ConvertParameter={StaticResource MyClass}/>

从 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

<namespace:MyClass x:Key="MyClass">

<Binding ... ConvertParameter={StaticResource MyClass}/>

from MyClass you can return anything you want ;)

this post can be helpful

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文