Esempio n. 1
0
        public PickListWindow(User user, string caption, Func<IEnumerable<object>> itemsFunc, Func<String, bool> addItemFunc, string initialFilter = "", Control PositionUnder = null, Control PositionUnderAncestor = null)
        {
            _itemsFunc = itemsFunc;
            _addItemFunc = addItemFunc;
            this.User = user;
            InitializeComponent();
            LaunchingControl = PositionUnder;

            if (PositionUnder == null || PositionUnderAncestor == null) {
                Config.RestoreWindowPosition(user, this);
            } else {
                Owner = PositionUnder.FindParentWindow();
                GeneralTransform transform = PositionUnder.TransformToAncestor(PositionUnderAncestor);
                var rootPoint = PositionUnder.PointToScreen(transform.Transform(new Point(0, 0)));
                Top = rootPoint.Y + PositionUnder.ActualHeight;
                Left = rootPoint.X;
                Width = PositionUnder.ActualWidth;
                Height = 250;
            }

            Title = caption;
            LoadModel();

            if (!string.IsNullOrWhiteSpace(initialFilter)) {
                txtFilter.Text = initialFilter;
            }

            btnAddNew.Visibility = System.Windows.Visibility.Hidden;

            if (_addItemFunc != null) {
                btnAddNew.Visibility = Visibility.Visible;
                btnAddNew.Click += new RoutedEventHandler((source, e) => {
                    string prefill = txtFilter.Text;
                    InputBox.Show(this, "Add a new value", "Enter the new value, and click OK", prefill, (text) => {
                        if (_addItemFunc(text)) {
                            _model.Add(text);
                            lst.SelectedItem = text;
                            this.DialogResult = true;
                            this.Hide();
                        }
                    });
                });
            }
        }