Browse Source

add items at selected index, or at end if no selection.

pull/554/head
danwalmsley 10 years ago
parent
commit
94f8abbc4d
  1. 3
      samples/VirtualizationTest/MainWindow.xaml
  2. 25
      samples/VirtualizationTest/ViewModels/MainWindowViewModel.cs

3
samples/VirtualizationTest/MainWindow.xaml

@ -20,8 +20,7 @@
<TextBox Watermark="Item to Create"
UseFloatingWatermark="True"
Text="{Binding NewItemString}"/>
<Button Command="{Binding PrePendItemCommand}">Pre-Pend Item</Button>
<Button Command="{Binding AppendItemCommand}">Append Item</Button>
<Button Command="{Binding AddItemCommand}">Add Item</Button>
<Button Command="{Binding RemoveItemCommand}">Remove Item</Button>
<Button Command="{Binding RecreateCommand}">Recreate</Button>
</StackPanel>

25
samples/VirtualizationTest/ViewModels/MainWindowViewModel.cs

@ -21,11 +21,8 @@ namespace VirtualizationTest.ViewModels
RecreateCommand = ReactiveCommand.Create();
RecreateCommand.Subscribe(_ => Recreate());
AppendItemCommand = ReactiveCommand.Create();
AppendItemCommand.Subscribe(_ => Append());
PrePendItemCommand = ReactiveCommand.Create();
PrePendItemCommand.Subscribe(_ => PrePend());
AddItemCommand = ReactiveCommand.Create();
AddItemCommand.Subscribe(_ => AddItem());
RemoveItemCommand = ReactiveCommand.Create();
RemoveItemCommand.Subscribe(_ => Remove());
@ -55,9 +52,7 @@ namespace VirtualizationTest.ViewModels
private set { this.RaiseAndSetIfChanged(ref _items, value); }
}
public ReactiveCommand<object> AppendItemCommand { get; private set; }
public ReactiveCommand<object> PrePendItemCommand { get; private set; }
public ReactiveCommand<object> AddItemCommand { get; private set; }
public ReactiveCommand<object> RecreateCommand { get; private set; }
@ -83,14 +78,16 @@ namespace VirtualizationTest.ViewModels
}
}
private void Append()
private void AddItem()
{
Items.Add(new ItemViewModel(Items.Count, NewItemString));
}
var index = Items.Count;
private void PrePend ()
{
Items.Insert(0, new ItemViewModel(0, NewItemString));
if (SelectedItem != null)
{
index = Items.IndexOf(SelectedItem);
}
Items.Insert(index, new ItemViewModel(index, NewItemString));
}
private void Remove()

Loading…
Cancel
Save