开发者

Combobox binding and updating other property

开发者 https://www.devze.com 2023-03-19 05:06 出处:网络
I have following XAML inside data grid: <DataTrigger Binding=\"{Binding Type}\" Value=\"3\"> <Setter TargetName=\"content\" Property=\"ContentTemplate\">

I have following XAML inside data grid:

<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>

What it does - when "Type = 3" - cell displays ComboBox. Than I parse "List" property inside my DelimitedListToItemsSource converter List looks like "Value 1|0|Value 2|1|Value 3|3" - basically key/value array in delimited stri开发者_如何学运维ng.

What I want to do is to bind SelectedValue to "value" part of of my delimited string.

I think I need to write another value converter for ItemsSource but I don't know how to get "List" property passed in there? It binds to "Value" property

So, I guess question boils down to passing object reference into value converter so I can set actual converted value based on other data in object..

And, if you read whole question and I'm doing it wrong alltogether - I welcome suggestions..


You cannot pass more than one bound value to a regular Converter.

You can either setup a MultiConverter which takes two parameters (SelectedValue and ValueList) and returns the correct item, or change your Converter so it returns a list of Key/Value pairs and bind your ComboBox's SelectedValuePath="Key" and DisplayMemberPath="Value"

0

精彩评论

暂无评论...
验证码 换一张
取 消