本文整理汇总了C#中ObservableCollection.Move方法的典型用法代码示例。如果您正苦于以下问题:C# ObservableCollection.Move方法的具体用法?C# ObservableCollection.Move怎么用?C# ObservableCollection.Move使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ObservableCollection
的用法示例。
在下文中一共展示了ObservableCollection.Move方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Follows_observed_collection
public void Follows_observed_collection()
{
var subject = new ObservableCollection<int>(new[] { 11, 12, 13, 14, 15, 16 });
var observer = new ObserverCollection<int>();
observer.Observe(subject);
EnumerableAssert.AreEqual(subject, observer);
subject.Insert(3, 77);
EnumerableAssert.AreEqual(subject, observer);
subject.Add(21);
EnumerableAssert.AreEqual(subject, observer);
subject.RemoveAt(0);
EnumerableAssert.AreEqual(subject, observer);
subject.RemoveAt(subject.Count - 1);
EnumerableAssert.AreEqual(subject, observer);
subject.Move(3, 0);
EnumerableAssert.AreEqual(subject, observer);
subject.Move(1, 5);
EnumerableAssert.AreEqual(subject, observer);
subject[4] = 777;
EnumerableAssert.AreEqual(subject, observer);
}
示例2: Move_Sync_IsCorrect
public void Move_Sync_IsCorrect()
{
ObservableCollection<Model> models = new ObservableCollection<Model>();
models.Add(new Model { SomeProperty = "A", });
models.Add(new Model { SomeProperty = "B", });
models.Add(new Model { SomeProperty = "C", });
ObservableCollection<ViewModel> viewModels = new ObservableCollection<ViewModel>();
foreach(var model in models)
viewModels.Add(new ViewModel(model));
models.CollectionChanged += (s, e) => ObservableCollectionSyncHelper.Sync(models, viewModels, e, (m) => new ViewModel(m), (vm) => vm.Model);
Assert.AreEqual("A", viewModels[0].Model.SomeProperty);
Assert.AreEqual("B", viewModels[1].Model.SomeProperty);
Assert.AreEqual("C", viewModels[2].Model.SomeProperty);
models.Move(2, 0);
Assert.AreEqual("C", viewModels[0].Model.SomeProperty);
Assert.AreEqual("A", viewModels[1].Model.SomeProperty);
Assert.AreEqual("B", viewModels[2].Model.SomeProperty);
models.Move(0, 2);
Assert.AreEqual("A", viewModels[0].Model.SomeProperty);
Assert.AreEqual("B", viewModels[1].Model.SomeProperty);
Assert.AreEqual("C", viewModels[2].Model.SomeProperty);
}
示例3: Result_updated_after_Move
public void Result_updated_after_Move()
{
var subject = new ObservableCollection<int>(new [] { 0, 1, 2, 3, 4, 5, 6, 7 });
var result = subject.ToQueryable().Where(i => i % 2 == 0).ToObservable();
Assert.IsInstanceOfType(result, typeof(IQueryableObservableCollection<int>));
subject.Move(1, 5);
Assert.AreEqual(0, result[0]);
Assert.AreEqual(2, result[1]);
Assert.AreEqual(4, result[2]);
Assert.AreEqual(6, result[3]);
Assert.AreEqual(4, result.Count);
subject.Move(0, 2);
Assert.AreEqual(2, result[0]);
Assert.AreEqual(0, result[1]);
Assert.AreEqual(4, result[2]);
Assert.AreEqual(6, result[3]);
Assert.AreEqual(4, result.Count);
subject.Move(0, 7);
Assert.AreEqual(0, result[0]);
Assert.AreEqual(4, result[1]);
Assert.AreEqual(6, result[2]);
Assert.AreEqual(2, result[3]);
Assert.AreEqual(4, result.Count);
subject.Move(7, 0);
Assert.AreEqual(2, result[0]);
Assert.AreEqual(0, result[1]);
Assert.AreEqual(4, result[2]);
Assert.AreEqual(6, result[3]);
Assert.AreEqual(4, result.Count);
subject.Move(2, 0);
Assert.AreEqual(0, result[0]);
Assert.AreEqual(2, result[1]);
Assert.AreEqual(4, result[2]);
Assert.AreEqual(6, result[3]);
Assert.AreEqual(4, result.Count);
subject.Move(5, 1);
Assert.AreEqual(0, result[0]);
Assert.AreEqual(2, result[1]);
Assert.AreEqual(4, result[2]);
Assert.AreEqual(6, result[3]);
Assert.AreEqual(4, result.Count);
}
示例4: MainWindowViewModel
public MainWindowViewModel()
{
Items = new ObservableCollection<TestItem>(
Enumerable.Range(0, 20).Select(x => new TestItem
{
StringValue = "Item " + x,
Detail = "Item " + x + " details",
}));
SelectedItems = new ObservableCollection<TestItem>();
ShuffleItems = ReactiveCommand.Create();
ShuffleItems.Subscribe(_ =>
{
var r = new Random();
Items.Move(r.Next(Items.Count), 1);
});
StringValueCommand = ReactiveCommand.Create();
StringValueCommand.Subscribe(param =>
{
BooleanFlag = !BooleanFlag;
StringValue = param.ToString();
});
}
示例5: MainWindowViewModel
public MainWindowViewModel()
{
Items = new ObservableCollection<TestItem>(
Enumerable.Range(0, 20).Select(x => new TestItem
{
StringValue = "Item " + x,
Detail = "Item " + x + " details",
}));
SelectedItems = new ObservableCollection<TestItem>();
ShuffleItems = ReactiveCommand.Create();
ShuffleItems.Subscribe(_ =>
{
var r = new Random();
Items.Move(r.Next(Items.Count), 1);
});
StringValueCommand = ReactiveCommand.Create();
StringValueCommand.Subscribe(param =>
{
BooleanFlag = !BooleanFlag;
StringValue = param.ToString();
});
Task.Run(() =>
{
while (true)
{
CurrentTime = DateTimeOffset.Now.ToString();
Thread.Sleep(1000);
}
});
}
示例6: On_move
public void On_move()
{
var original = new[] { 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20 };
ObservableCollection<int> subject;
IReadOnlyList<int> sherlock;
var changes = new Queue<NotifyCollectionChangedEventArgs>();
subject = new ObservableCollection<int>(original);
subject.CollectionChanged += (s, e) => changes.Enqueue(e);
subject.Move(3, 0);
sherlock = subject.Rewind(changes.Dequeue());
EnumerableAssert.AreEqual(original, sherlock);
subject = new ObservableCollection<int>(original);
subject.CollectionChanged += (s, e) => changes.Enqueue(e);
subject.Move(0, 7);
sherlock = subject.Rewind(changes.Dequeue());
EnumerableAssert.AreEqual(original, sherlock);
subject = new ObservableCollection<int>(original);
subject.CollectionChanged += (s, e) => changes.Enqueue(e);
subject.Move(8, 0);
sherlock = subject.Rewind(changes.Dequeue());
EnumerableAssert.AreEqual(original, sherlock);
}
示例7: Select_Is_Updated_On_Move
public void Select_Is_Updated_On_Move()
{
var subject = new ObservableCollection<int>(new [] { 0, 1, 2, 3, 4, 5, 6, 7 });
var result = subject.ToQueryable().Select(i => i * 2).ToObservable();
subject.Move(3, 7);
Assert.AreEqual(4, result[2]);
Assert.AreEqual(8, result[3]);
Assert.AreEqual(10, result[4]);
Assert.AreEqual(6, result[7]);
}
示例8: setCurrentViewOrder
private void setCurrentViewOrder(ObservableCollection<int> userOrder, ObservableCollection<int> curOrder)
{
var viewColumns = (listView.View as GridView).Columns;
// ユーザー指定のカラム順番に並び替える
for (var i = 0; i < Count; ++ i)
{
var ci = curOrder.IndexOf(userOrder[i]);
viewColumns.Move(ci, i);
curOrder.Move(ci, i); // カラム順番をViewから取得できないためここで追従
}
}
示例9: MainWindowViewModel
public MainWindowViewModel()
{
Items = new ObservableCollection<TestItem>
{
new TestItem { StringValue = "Foo" },
new TestItem { StringValue = "Bar" },
new TestItem { StringValue = "Baz" },
};
ShuffleItems = ReactiveCommand.Create();
ShuffleItems.Subscribe(_ =>
{
var r = new Random();
Items.Move(r.Next(Items.Count), 1);
});
}
示例10: MainWindowViewModel
public MainWindowViewModel()
{
Items = new ObservableCollection<TestItem>(
Enumerable.Range(0, 20).Select(x => new TestItem
{
StringValue = "Item " + x
}));
SelectedItems = new ObservableCollection<TestItem>();
ShuffleItems = ReactiveCommand.Create();
ShuffleItems.Subscribe(_ =>
{
var r = new Random();
Items.Move(r.Next(Items.Count), 1);
});
}
示例11: Move
public void Move()
{
List<string> applied = new List<string> { "foo", "bar", "baz" };
Action reset = () => Assert.Fail ("Reset should not be called");
Action<object, int, bool> insert = (o, i, create) => {
Assert.That (create, Is.False);
applied.Insert (i, (string) o);
};
Action<object, int> removeAt = (o, i) => applied.RemoveAt (i);
var items = new ObservableCollection<string> (applied);
items.CollectionChanged += (s, e) => e.Apply (insert, removeAt, reset);
items.Move (0, 2);
CollectionAssert.AreEqual (items, applied);
}
示例12: ReorderListBoxPage
public ReorderListBoxPage()
{
var brushes = new ObservableCollection<SolidColorBrush>(App.DemoColors.Select(c => c.ToCachedBrush()));
DataContext = brushes;
AddHandler(
ReorderListBox.ReorderRequestedEvent,
new EventHandler<ReorderEventArgs>(
delegate(object sender, ReorderEventArgs args) {
var reorderListBox = (ReorderListBox)args.OriginalSource;
var draggingBrush = (SolidColorBrush)reorderListBox.ItemContainerGenerator.ItemFromContainer(args.ItemContainer);
var toBrush = (SolidColorBrush)reorderListBox.ItemContainerGenerator.ItemFromContainer(args.ToContainer);
brushes.Move(brushes.IndexOf(draggingBrush), brushes.IndexOf(toBrush));
}));
InitializeComponent();
}
示例13: Cozy
public static void Cozy()
{
Console.WriteLine("\n-----------------------------------------------");
Console.WriteLine(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType.FullName);
Console.WriteLine("-----------------------------------------------");
var observableList = new ObservableCollection<string>();
observableList.CollectionChanged += (s, e) =>
{
Console.WriteLine("执行的操作是{0}", e.Action);
switch (e.Action)
{
case NotifyCollectionChangedAction.Add:
Console.WriteLine("新增了一个元素:{0}", ((IList<string>)s)[e.NewStartingIndex]);
break;
case NotifyCollectionChangedAction.Remove:
Console.WriteLine("移除了一个元素:{0}", e.OldItems[e.OldStartingIndex]);
break;
case NotifyCollectionChangedAction.Move:
Console.WriteLine("移动了一个元素:{0}", e.OldItems[e.OldStartingIndex]);
break;
case NotifyCollectionChangedAction.Replace:
Console.WriteLine("替换了一个元素:{0}", e.OldItems[e.OldStartingIndex]);
break;
case NotifyCollectionChangedAction.Reset:
Console.WriteLine("集合的内容发生显著更改");
break;
default:
return;
}
};
observableList.Add("Hello");
observableList.Add("world");
observableList.Move(0, 1);
observableList[0] = "Replace";
observableList.Remove("Replace");
observableList.Clear();
}
示例14: Collection_Changed
void Collection_Changed(ObservableCollection<SettingsPath> sender, ObservableCollection<SettingsPathViewModel> destination, SettingsPathType type, System.Collections.Specialized.NotifyCollectionChangedEventArgs e)
{
switch (e.Action)
{
case System.Collections.Specialized.NotifyCollectionChangedAction.Add:
{
var vm = new SettingsPathViewModel(e.NewItems[0] as SettingsPath, type);
vm.IsAdded = true;
destination.Add(vm);
};
break;
case System.Collections.Specialized.NotifyCollectionChangedAction.Move:
{
destination.Move(e.OldStartingIndex, e.NewStartingIndex);
}
break;
case System.Collections.Specialized.NotifyCollectionChangedAction.Remove:
{
destination.RemoveAt(e.OldStartingIndex);
}
break;
case System.Collections.Specialized.NotifyCollectionChangedAction.Replace:
{
var vm = new SettingsPathViewModel(e.NewItems[0] as SettingsPath, type);
vm.IsAdded = true;
destination[e.OldStartingIndex] = vm;
}
break;
case System.Collections.Specialized.NotifyCollectionChangedAction.Reset:
{
BuildPathViewModels(sender, destination, type);
}
break;
default:
break;
}
}
示例15: Result_is_updated_after_Move
public void Result_is_updated_after_Move()
{
var subject = new ObservableCollection<int>(new [] { 10, 11, 12, 11, 12, 10, 12, 17 });
var result = subject.ToQueryable().Distinct().ToObservable();
var expected = subject.Distinct();
Assert.IsInstanceOfType(result, typeof(IQueryableObservableCollection<int>));
var events = new Queue<NotifyCollectionChangedEventArgs>();
result.CollectionChanged += (s, e) => events.Enqueue(e);
subject.Move(4, 7);
expected = subject.Distinct();
EnumerableAssert.AreEqual(result, expected);
Assert.AreEqual(0, events.Count);
subject.Move(3, 0);
expected = subject.Distinct();
EnumerableAssert.AreEqual(result, expected);
Assert.AreEqual(NotifyCollectionChangedAction.Move, events.Dequeue().Action);
subject.Move(2, 1);
expected = subject.Distinct();
EnumerableAssert.AreEqual(result, expected);
Assert.AreEqual(0, events.Count);
subject.Move(5, 1);
expected = subject.Distinct();
EnumerableAssert.AreEqual(result, expected);
Assert.AreEqual(NotifyCollectionChangedAction.Move, events.Dequeue().Action);
}