Click here to Skip to main content
13,259,194 members (51,037 online)
Rate this:
 
Please Sign up or sign in to vote.
I've got the following two combo boxes. One updates the content when the SortedList changes and the other doesn't.
<ComboBox Name="cbxNotUpdating"
  ItemsSource="{Binding Path=DataContext.Versions.Values, RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type Window}}}"
  SelectedValue="{Binding Path=Version, Mode=TwoWay}">
</ComboBox>
 
<ComboBox Name="cbxUpdating"
  ItemsSource="{Binding Path=DataContext.Versions, RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type Window}}}"
    SelectedValue="{Binding Path=Version, Mode=TwoWay}">
</ComboBox>


The obvious difference is that cbxNotUpdating binds to the Values and cbxUpdating binds to the SortedList itself.
My List implementation looks like this:
public class VersionList : SortedList<string, Version>, INotifyCollectionChanged
{
...
  public event NotifyCollectionChangedEventHandler CollectionChanged;
  protected virtual void OnCollectionChanged(NotifyCollectionChangedEventArgs e)
  {
      if (CollectionChanged != null)
      {
          CollectionChanged(this, e);
      }
  }
}

How can I make the cbxNotUpdating update?
I've got a property that is a 'Version' that I want to have as the SelectedValue at the same time I have a template that works on just the Value part of the collection.

I'm using vs2010.
Posted 20-Jan-12 6:01am
Erik Rude5.1K
Updated 20-Jan-12 7:15am
v2
Comments
SteveAdey 20-Jan-12 11:29am
   
The difference is that the Values are just an IList<tvalue> which has no mechanism to notify of its changes.

What are you trying to achieve with cbxNotUpdating that you cannot with cbxUpdating?
Erik Rude 20-Jan-12 12:17pm
   
Thanks fo rthe reply - I've got a property that is a 'Version' that I want to have as the SelectedValue at the same time (this doesn't work in the cbxUpdating) I have a template that works on just the Value part of the collection. I refer to that just on the DataType eg:
<datatemplate x:key="VersionTemplate" datatype="{x:Type MyApp:Version}" xmlns:x="#unknown">
Erik Rude 20-Jan-12 12:21pm
   
I will try to work around this then. I just thought that the Values would automatically refresh when the collection did.

1 solution

Rate this: bad
 
good
Please Sign up or sign in to vote.

Solution 1

Thanks to SteveAdey for pointing out the fatal flaw.
In the end I bound to the SortedList changed the SelectedValuePath and used a DataTemplate binding to the Value to get to my desired goal.
My solution looks like this:

<ComboBox Name="cbxFolder" Grid.Column="1" Grid.Row="0"
                ItemsSource="{Binding Path=DataContext.Versions, RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type Window}}}"
                SelectedValue="{Binding Path=Version, Mode=TwoWay}"
                SelectedValuePath="Value"
                ComboBox.ItemTemplate="{StaticResource VersionCbxTemplate}">
</ComboBox>

With this DataTemplate in the resources
<DataTemplate x:Key="saturnVersioncbx">
  <StackPanel Margin="5" DataContext="{Binding Value}" >...
  </StackPanel>
</DataTemplate>
  Permalink  

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Top Experts
Last 24hrsThis month


Advertise | Privacy |
Web03 | 2.8.171114.1 | Last Updated 23 Jan 2012
Copyright © CodeProject, 1999-2017
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100