예제 #1
0
        internal void SetComponentLinks(IEnumerable <AbstractEndpoint.IAbstractComponentLink> componentLinks)
        {
            var links = new List <ComponentsOrderingViewModel>();

            var setOrder = new Action(() =>
            {
                var worker     = new BackgroundWorker();
                worker.DoWork += (e, s) =>
                {
                    foreach (var cl in links.AsEnumerable().Reverse())
                    {
                        cl.Link.Order = links.IndexOf(cl) + 1;
                    }
                };
                worker.RunWorkerAsync();
            });

            foreach (var cl in componentLinks.OrderBy(x => x.Order))
            {
                var vm = new ComponentsOrderingViewModel {
                    Link = cl
                };
                links.Add(vm);
                vm.UpCommand = new RelayCommand(
                    () =>
                {
                    var prevIndex = links.IndexOf(vm);
                    links.Remove(vm);
                    links.Insert(prevIndex - 1, vm);
                    this.ComponentList.ItemsSource  = null;
                    this.ComponentList.ItemsSource  = links;
                    this.ComponentList.SelectedItem = vm;
                    setOrder();
                }, () => links.IndexOf(vm) > 0);
                vm.DownCommand = new RelayCommand(
                    () =>
                {
                    var prevIndex = links.IndexOf(vm);
                    links.Remove(vm);
                    links.Insert(prevIndex + 1, vm);
                    this.ComponentList.ItemsSource  = null;
                    this.ComponentList.ItemsSource  = links;
                    this.ComponentList.SelectedItem = vm;
                    setOrder();
                }, () => links.IndexOf(vm) < links.Count - 1);
            }
            this.ComponentList.ItemsSource = links;
        }
        internal void SetComponentLinks(IEnumerable<AbstractEndpoint.IAbstractComponentLink> componentLinks)
        {
            var links = new List<ComponentsOrderingViewModel>();

            var setOrder = new Action(() =>
                {
                    var worker = new BackgroundWorker();
                    worker.DoWork += (e, s) =>
                    {
                        foreach (var cl in links.AsEnumerable().Reverse())
                        {
                            cl.Link.Order = links.IndexOf(cl) + 1;
                        }
                    };
                    worker.RunWorkerAsync();
                });
            foreach (var cl in componentLinks.OrderBy(x => x.Order))
            {
                var vm = new ComponentsOrderingViewModel { Link = cl };
                links.Add(vm);
                vm.UpCommand = new RelayCommand(
                    () =>
                    {
                        var prevIndex = links.IndexOf(vm);
                        links.Remove(vm);
                        links.Insert(prevIndex - 1, vm);
                        this.ComponentList.ItemsSource = null;
                        this.ComponentList.ItemsSource = links;
                        this.ComponentList.SelectedItem = vm;
                        setOrder();
                    }, () => links.IndexOf(vm) > 0);
                vm.DownCommand = new RelayCommand(
                    () =>
                    {
                        var prevIndex = links.IndexOf(vm);
                        links.Remove(vm);
                        links.Insert(prevIndex + 1, vm);
                        this.ComponentList.ItemsSource = null;
                        this.ComponentList.ItemsSource = links;
                        this.ComponentList.SelectedItem = vm;
                        setOrder();
                    }, () => links.IndexOf(vm) < links.Count - 1);
            }
            this.ComponentList.ItemsSource = links;
        }