【问题标题】:MultipleBinding for a WPF Converter... when does ConvertBack get called?WPF 转换器的 MultipleBinding... ConvertBack 何时被调用?
【发布时间】:2012-08-19 01:35:46
【问题描述】:

我有一个带有一组值的 ComboBox。所选值由具有多个双向绑定的 Converter 确定。当用户更改 ComboBox 中的值时,我希望调用 ConvertBack 方法并更改多重绑定中使用的两个属性的值,但这不会发生,即使 ComboBox 失去焦点也是如此。我试图将 UpdateSourceTrigger 属性更改为“LosesFocus”,但这显然对 MultipleBinding 无效。如何在值更改或控件失去焦点时触发 ConvertBack 方法?两者都可以满足我的目的。

XAML:

<ComboBox ItemsSource="{Binding DescriptionList}" DisplayMemberPath="Description" SelectedValuePath="Description" IsEnabled="{Binding EditMode}">
    <ComboBox.SelectedValue>
        <MultiBinding Converter="{StaticResource DescriptionConverter}">
            <Binding Path="PersonRow.DescriptionType" Mode="TwoWay" UpdateSourceTrigger="PropertyChanged" />
            <Binding Path="PersonRow.DescriptionSuccessful" Mode="TwoWay" UpdateSourceTrigger="PropertyChanged" />
        </MultiBinding>
    </ComboBox.SelectedValue>
</ComboBox>

【问题讨论】:

    标签: .net wpf xaml updatesourcetrigger


    【解决方案1】:

    您可能需要将Mode="TwoWay" 添加到您的&lt;MultiBinding&gt;

    【讨论】:

    • 我尝试将 Mode="TwoWay" 添加到 MutiBinding 标记,但 ConvertBack 方法仍然没有触发。
    • @jpaull 我还要从子绑定中删除 ModeUpdateSourceTrigger 属性。您也可以尝试在MultiBinding 上添加UpdateSourceTrigger
    【解决方案2】:

    Jay 的建议为我指明了正确的方向。我还在 MultiBinding 标记中添加了一个 UpdateSourceTrigger="LostFocus" 并且能够触发该事件。

    【讨论】:

      猜你喜欢
      • 2014-02-12
      • 2011-05-31
      • 1970-01-01
      • 1970-01-01
      • 2011-08-17
      • 2019-12-25
      • 1970-01-01
      • 2019-04-11
      • 1970-01-01
      相关资源
      最近更新 更多