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" <TextBox Watermark="Item to Create"
UseFloatingWatermark="True" UseFloatingWatermark="True"
Text="{Binding NewItemString}"/> Text="{Binding NewItemString}"/>
<Button Command="{Binding PrePendItemCommand}">Pre-Pend Item</Button> <Button Command="{Binding AddItemCommand}">Add Item</Button>
<Button Command="{Binding AppendItemCommand}">Append Item</Button>
<Button Command="{Binding RemoveItemCommand}">Remove Item</Button> <Button Command="{Binding RemoveItemCommand}">Remove Item</Button>
<Button Command="{Binding RecreateCommand}">Recreate</Button> <Button Command="{Binding RecreateCommand}">Recreate</Button>
</StackPanel> </StackPanel>

25
samples/VirtualizationTest/ViewModels/MainWindowViewModel.cs

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

Loading…
Cancel
Save