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 的 XAML,它构成了封面流类型控件的数据模板的一部分。

<TextBlock HorizontalAlignment="Left" Margin="2,0,0,0" Text="{Binding Converter={StaticResource DateConverter}, Path=Date, ConverterParameter={Binding Recognition, Path=Frequency}}" />

谁能看到我要去哪里错了?

4

1 回答 1

0

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

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

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

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

从 MyClass 你可以返回任何你想要的东西;)

这篇文章可能会有所帮助

于 2010-10-28T21:37:04.747 回答