Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>I don't get this part: </p> <blockquote> <p>I call MoveUp and MoveDown methods of Observable Collection.</p> </blockquote> <p>ObservableCollection does not have such methods, at least not to my knowledge? Neither has it a notion of a current item or similar. </p> <p>My apologies if I have missed something that could possibly render this post as ignorant. </p> <p>What you could do is instead of binding your ListView to an ObservableCollection, you could bind it to a ICollectionView (derived from your ObservableCollection). If you set IsSynchronizedWithCurrentItem=True on ListView, you won't need to bind SelectedItem, it will be automatically bound to CurrentItem on ICollectionView. </p> <p>ICollectionView also implements MoveCurrentToNext and MoveCurrentCurrentToPrevious which can be bound from your buttons (via ICommand).</p> <p><strong>EDIT:</strong> Now that new information is on the table, my above answer is not really relevant anymore. But I don't (yet) know the SO convention how to handle this, if I should delete the post entirely, edit out the above or just add the "new" reply. For now I'll edit this post.</p> <p>I tried to recreate your project and your problem. Hopefully I have understood your problem right, and recreated it similarly at least. </p> <p>As in the problem being the combobox not holding its value when it is being moved in the listview, it works for me. </p> <p>Below are the relevant code (some of it hidden to avoid too much noise). </p> <p>Does this help you?</p> <pre><code>public class MainWindowViewModel:INotifyPropertyChanged { private Condition _selectedCondition; public ObservableCollection&lt;Condition&gt; Conditions { get; set; } public Condition SelectedCondition { get { return _selectedCondition; } set { if (_selectedCondition != value) { _selectedCondition = value; OnPropertyChanged("SelectedCondition"); } } } ... public void MoveUpExecuted() { int oldIndex = this.Conditions.IndexOf(_selectedCondition); //Check if the selected item is not the first item if (oldIndex != 0) { int newIndex = oldIndex - 1; this.Conditions.Move(oldIndex, newIndex); } } </code></pre> <p>And the condition class:</p> <pre><code>public class Condition : INotifyPropertyChanged { private MyType myType; public ObservableCollection&lt;MyType&gt; MyTypes { get; set; } public MyType MyType { get { return myType; } set { if (myType != value) { myType = value; OnPropertyChanged("MyType"); } } } public Condition() { MyTypes = new ObservableCollection&lt;MyType&gt;() { new MyType() { Key = "1", Value = "One" }, new MyType() { Key = "2", Value = "Two" } }; MyType = MyTypes[1]; } </code></pre> <p>... etc</p> <pre><code>&lt;ListView SelectedItem="{Binding Path=SelectedCondition}" ItemsSource="{Binding Path=Conditions}" FontWeight="Normal" FontSize="11" Name="listview" Margin="0,32,0,0"&gt; &lt;ListView.View&gt; &lt;GridView&gt; &lt;GridViewColumn Width="175" Header="Type"&gt; &lt;GridViewColumn.CellTemplate&gt; &lt;DataTemplate&gt; &lt;ComboBox Width="150" SelectedValuePath="Key" DisplayMemberPath="Value" SelectedItem="{Binding Path=MyType}" ItemsSource="{Binding Path=MyTypes}" HorizontalAlignment="Center" /&gt; &lt;/DataTemplate&gt; &lt;/GridViewColumn.CellTemplate&gt; &lt;/GridViewColumn&gt; &lt;/GridView&gt; &lt;/ListView.View&gt; &lt;/ListView&gt; &lt;Button Content="Move up" Command="{Binding MoveUpCommand}" /&gt; </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload