private void RemoveSelected()
        {
            var index = SelectedRenderingsListBox.SelectedIndex;

            var selectedItems = SelectedRenderingsListBox.SelectedItems.OfType <ListBoxItem>().Select(listBoxItem => listBoxItem.Tag).OfType <ItemHeader>().Select(itemHeader => itemHeader.ItemId).ToList();

            foreach (var selectedItem in selectedItems)
            {
                RenderingPicker.Remove(selectedItem);
            }

            // workaround for WPF quirk when checkbox is not visible, the Checked event does not fire
            SelectedItems = RenderingPicker.SelectedItems;
            Refresh();

            if (index >= SelectedRenderingsListBox.Items.Count)
            {
                index = SelectedRenderingsListBox.Items.Count - 1;
            }

            if (index >= 0)
            {
                SelectedRenderingsListBox.SelectedIndex = index;
            }
        }
        public void Initialize([NotNull] string title, [NotNull] DatabaseUri databaseUri, [NotNull] IEnumerable <ItemId> selectedRenderings)
        {
            Assert.ArgumentNotNull(title, nameof(title));
            Assert.ArgumentNotNull(databaseUri, nameof(databaseUri));
            Assert.ArgumentNotNull(selectedRenderings, nameof(selectedRenderings));

            Title         = title;
            SelectedItems = new List <ItemId>(selectedRenderings);

            RenderingPicker.Initialize(databaseUri, selectedRenderings);
        }
        private void SetSelection([NotNull] object sender, [NotNull] SelectionChangedEventArgs e)
        {
            Debug.ArgumentNotNull(sender, nameof(sender));
            Debug.ArgumentNotNull(e, nameof(e));

            var selectedItem = SelectedRenderingsListBox.SelectedItems.OfType <ListBoxItem>().Select(listBoxItem => listBoxItem.Tag).OfType <ItemHeader>().Select(itemHeader => itemHeader.ItemId).FirstOrDefault();

            if (selectedItem == null)
            {
                return;
            }

            RenderingPicker.FocusItem(selectedItem);
        }
        private void Refresh()
        {
            SelectedRenderingsListBox.Items.Clear();

            foreach (var selectedItem in SelectedItems)
            {
                var itemHeader = RenderingPicker.GetItemHeader(selectedItem);
                if (itemHeader == null)
                {
                    continue;
                }

                var listBoxItem = new ListBoxItem
                {
                    Tag     = itemHeader,
                    Content = itemHeader.Name
                };

                SelectedRenderingsListBox.Items.Add(listBoxItem);
            }
        }