示例#1
0
        private void AddFileToDatabase(DatabaseReference database)
        {
            var dialog = new OpenFileDialog()
            {
                Filter      = "All files|*.*",
                Multiselect = false
            };

            if (dialog.ShowDialog() != true)
            {
                return;
            }

            try
            {
                if (InputBoxWindow.ShowDialog("New file id:", "Enter new file id", Path.GetFileName(dialog.FileName), out string id) == true)
                {
                    var file = database.AddFile(id, dialog.FileName);
                    SelectedCollection = database.Collections.First(a => a.Name == "_files");
                    ListCollectionData.SelectedItem = file;
                    ListCollectionData.ScrollIntoView(ListCollectionData.SelectedItem);
                }
            }
            catch (Exception exc)
            {
                MessageBox.Show(
                    "Failed to upload file:" + Environment.NewLine + exc.Message,
                    "Database error",
                    MessageBoxButton.OK,
                    MessageBoxImage.Error
                    );
            }
        }
示例#2
0
        public CollectionListView()
        {
            InitializeComponent();

            ListCollectionData.MouseDoubleClick += ListCollectionDataOnMouseDoubleClick;
            ListCollectionData.SelectionChanged += OnListViewSelectionChanged;

            ListCollectionData.SetBinding(Selector.SelectedItemProperty, new Binding
            {
                Source = this,
                Path   = new PropertyPath(nameof(SelectedItem)),
                Mode   = BindingMode.TwoWay
            });

            ListCollectionData.Loaded += (sender, args) =>
            {
                Dispatcher.BeginInvoke(DispatcherPriority.Render, (Action)(() =>
                {
                    var maxWidth = Math.Max(600, ListCollectionData.ActualWidth) / Math.Min(3, GridCollectionData.Columns.Count + 1);
                    foreach (var col in GridCollectionData.Columns)
                    {
                        col.Width = col.ActualWidth > maxWidth ? maxWidth : Math.Max(100, col.ActualWidth);
                    }
                }));
                _listLoaded = true;
            };
        }
        public CollectionListView()
        {
            InitializeComponent();

            ListCollectionData.MouseDoubleClick += ListCollectionDataOnMouseDoubleClick;
            ListCollectionData.SelectionChanged += OnListViewSelectionChanged;

            ListCollectionData.SetBinding(Selector.SelectedItemProperty, new Binding
            {
                Source = this,
                Path   = new PropertyPath(nameof(SelectedItem)),
                Mode   = BindingMode.TwoWay
            });
        }
示例#4
0
        private void AddCommand_Executed(object sender, ExecutedRoutedEventArgs e)
        {
            if (SelectedCollection is FileCollectionReference)
            {
                AddFileToDatabase(SelectedCollection.Database);
            }
            else
            {
                var newDoc = new BsonDocument
                {
                    ["_id"] = ObjectId.NewObjectId()
                };

                ListCollectionData.SelectedItem = SelectedCollection.AddItem(newDoc);
                ListCollectionData.ScrollIntoView(ListCollectionData.SelectedItem);
                UpdateGridColumns(newDoc);
            }
        }
示例#5
0
 private void SelectDocumentInView(DocumentReference document)
 {
     ListCollectionData.SelectedItem = document;
     ListCollectionData.ScrollIntoView(document);
 }