Question

Essentially, I want to use a combobox as a means to select an item to view, not update the item currently being viewed. Is it possible to do this using bindings rather than code?

Here's the code I have in the view:

<ComboBox DisplayMemberPath="CustomerId" SelectedValuePath="CustomerId" 
SelectedValue="{Binding Path=CustomerId}" ItemsSource="{Binding Mode=OneWay}" 
IsSynchronizedWithCurrentItem="True"/>

It will display the next member I select from the combo box, but it will also override the previous value of the customer I switched from.

(Also, my apologies for any poor etiquette; this is my first post here)

Edit: To clarify, the hierarchy of the window is as follows: A grid that contains text boxes and the combobox and that has the binding. The text boxes bind to various attributes of the "customer" class and then the combobox sets the selected customer.

So like this:

<Grid DataContext = "{Binding Customers}">
    <TextBox .../>
    ...
    <ComboBox (see code above)/>
</Grid>
Was it helpful?

Solution 2

Going to answer my own question on this one, oh well.

To fix this, I used this for my code:

        <ComboBox 
            DisplayMemberPath="CustomerId" 
            SelectedValuePath="CustomerId"
            SelectedValue="{Binding Path=CustomerId, Mode=OneWay, UpdateSourceTrigger=Explicit}" 
            ItemsSource="{Binding Mode=OneWay}" 
            IsSynchronizedWithCurrentItem="True"/>

If I don't specify the binding in the selected value to be a one way binding, it will then update the source. I thought the oneway binding in the itemsource was supposed to do that for me, but apparently that's not the case.

OTHER TIPS

Try this

<ComboBox DisplayMemberPath="CustomerId" SelectedValuePath="CustomerId" 
SelectedValue="{Binding Path=CustomerId, UpdateSourceTrigger=Explicit}" ItemsSource="{Binding   Mode=OneWay}" 
IsSynchronizedWithCurrentItem="False"/>

So you have to explicitly update your SelectedValue property to update in the code.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top