views:

27

answers:

3

Hi All,

I've got a listbox that contains a list of objects (lets say addresses)

The list box items source is bound to this observable collection

<ListBox x:Name="listDetails"
ItemsSource="{Binding}" 

...

Then i've got a text box, this is bound to the name fild of the current object

<TextBox x:Name="textBoxName" Text="{Binding Name, UpdateSourceTrigger=Explicit}"  />

So I expect that the Name property of my current object won't be change unless i explicitly update it..

However it is getting updated... any ideas to why?

Also this is in a window, if i close the window and reopen the window somehow the same selection on the listbox is preserved..

I'd expected once the window was closed then it would forget all about the current selection of it's listbox?

A: 

Looking at the stack trace it seems that when the list changes slection that the value of the Name property gets changed at that time...

I expect it never gets changed with the UpdateExplicit option set?

James Keating
A: 

Hi Santosc,

yes sorry I had one, seems like it got lost when i posted.

TextBox Text="{Binding Value, UpdateSourceTrigger=Explicit}"  />

<ListBox IsSynchronizedWithCurrentItem="True" ItemsSource="{Binding}" ....
James Keating
it si generally bad form to add answers to extend your question comments. Next time, try to edit your original question instead of answering yourself unless you have the answer.
santosc
ah ya, gotta, new to this forum. point taken.tnx
James Keating
A: 

Figured out how to solve it, i added an event to the listgbox

private void OnListValueChanged(object sender, SelectionChangedEventArgs e)
        {
            ListBox lb = e.Source as ListBox;
            if (lb != null)
            {
                object dc = null;
                if (lb.SelectedIndex != -1)
                    dc = lb.Items[lb.SelectedIndex];

                gridDetails.DataContext = dc;
            }
        }

the grid details context was set independently each and every time.

James Keating