如何绑定ConverterParameter

时间:2010-10-28 21:30:44

标签: c# xaml valueconverter

我正在尝试绑定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}}" />

有人能看到我出错的地方吗?

1 个答案:

答案 0 :(得分:0)

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

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

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

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

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

this帖子可以提供帮助