0

我有一个有趣的问题Binding,我有一个DataTemplate包含一个Button,并且DataTemplate已经放置在一个窗口(specView)中,我需要将它绑定Button.Command到一个Commnad内部窗口的视图模型,所以我这样做:

Command="{Binding DataContext.NewOfferNoCommand,ElementName=specView}"/>

但直到我创建一个返回值的转换器之前它不会被绑定:

public class ReturnValueConverter : IValueConverter
{
    public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
    {
        return value;
    }

    public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
    {
        return value;
    }
}

我真的不明白问题是什么?任何idia?

4

1 回答 1

0

You need to set the relative source in order for the binding to work.

{Binding DataContext.NewOfferNoCommand, RelativeSource={RelativeSource TemplatedParent}}
于 2012-12-06T09:34:10.420 回答