将Multivalueconverter的返回值绑定到属性

时间:2014-03-18 09:29:26

标签: c# wpf converter

我有一个多值转换器,它根据逻辑中的任何一个值返回两个值。我想是否可以将返回值绑定到另一个属性?

<DatePicker SelectedDate="{BindingStartDateTime,UpdateSourceTrigger=PropertyChanged,Mode=TwoWay}"
    Grid.Row="0" Grid.Column="2" Width="100"
    DisplayDate="{Binding ElementName=cmbDOS, Path=SelectedItem.FromDate}"
    HorizontalAlignment="Left" VerticalAlignment="Center" Margin="2,2,2,2" >
    <DatePicker.SelectedDate>
        <MultiBinding Converter="{StaticResource OperatorToListConverter}">
            <Binding Path="StartDateTime" />
            <Binding Path="SomeOtherDate"/>
        </MultiBinding>
    </DatePicker.SelectedDate>
</DatePicker>

根据我的逻辑,我将选择开始或某个日期,我希望它的值反映在StartDateTime中。这显然会给出错误,还有其他办法吗?

1 个答案:

答案 0 :(得分:1)

为什么不在视图模型中使用转换器的实例,在哪里需要值?:

SomeConverter converter = new Converter();
object[] values = {someObject.SomeProperty, someOtherObject.SomeProperty};
object result = 
    converter.Convert(values, typeof(SomeType), someParam, new CultureInfo("en-GB"));