【问题标题】:Combobox binding and updating other property组合框绑定和更新其他属性
【发布时间】:2011-07-11 15:52:14
【问题描述】:

我在数据网格中有以下 XAML:

<DataTrigger Binding="{Binding Type}" Value="3">
    <Setter TargetName="content" Property="ContentTemplate">
        <Setter.Value>
            <DataTemplate>
                <ComboBox 
                    SelectedValue="{Binding Value, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}"
                    ItemsSource="{Binding List, Converter={Converters:DelimitedListToItemsSource}}">
                </ComboBox>
            </DataTemplate>
        </Setter.Value>
    </Setter>
</DataTrigger>

它的作用 - 当“Type = 3” - 单元格显示ComboBox。 比我在我的 DelimitedListToItemsSource 转换器中解析“列表”属性 列表看起来像“Value 1|0|Value 2|1|Value 3|3” - 基本上是分隔字符串中的键/值数组。

我想要做的是将 SelectedValue 绑定到分隔字符串的“值”部分。

我想我需要为ItemsSource 编写另一个值转换器,但我不知道如何在其中传递“List”属性?它绑定到“值”属性

所以,我想问题归结为将对象引用传递给值转换器,以便我可以根据对象中的其他数据设置实际转换后的值..

而且,如果您阅读了整个问题并且我都做错了 - 我欢迎提出建议..

【问题讨论】:

  • 你的转换器返回的是什么类型的对象?
  • Converter 返回简单的 String[] 我从分隔字符串中丢弃每一秒的值。

标签: wpf xaml data-binding


【解决方案1】:

您不能将多个绑定值传递给常规转换器。

您可以设置一个 MultiConverter,它接受两个参数(SelectedValue 和 ValueList)并返回正确的项目,或者更改您的转换器,使其返回键/值对列表并绑定您的组合框的 SelectedValuePath="Key"DisplayMemberPath="Value"

【讨论】:

    猜你喜欢
    • 2011-09-19
    • 2012-06-04
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-02-22
    • 1970-01-01
    • 2016-11-03
    • 1970-01-01
    相关资源
    最近更新 更多