private void AddRow_Click(object sender, RoutedEventArgs e)
        {
            Button            b           = sender as Button;
            GridEditorContext editContext = this.DataContext as GridEditorContext;

            editContext.GridItems.Add(Activator.CreateInstance(editContext.ElementType));
        }
        private void Ok_Click(object sender, RoutedEventArgs e)
        {
            var errors = (from c in
                          (from object i in DataGrid.ItemsSource
                           select DataGrid.ItemContainerGenerator.ContainerFromItem(i))
                          where c != null
                          select Validation.GetHasError(c))
                         .FirstOrDefault(x => x);

            //In case of empty row was added but wasn't changed. Just remove it.
            if (!errors)
            {
                GridEditorContext editContext = this.DataContext as GridEditorContext;
                for (int i = 0; i < editContext.GridItems.Count; i++)
                {
                    if ((editContext.GridItems[i] as IValidateable).HasAnyValuesInTheFields())
                    {
                        continue;
                    }
                    editContext.GridItems.RemoveAt(i);
                    i--;
                }
            }

            if (errors)
            {
                if (MessageBox.Show("There are validation errors. Data will not be saved.\nProceed anyway?", "Invalid data",
                                    MessageBoxButton.YesNo) == MessageBoxResult.No)
                {
                    return;
                }
            }
            this.DialogResult = !errors;
            this.Close();
        }
        private void DeleteRow_Click(object sender, RoutedEventArgs e)
        {
            Button            b           = sender as Button;
            GridEditorContext editContext = this.DataContext as GridEditorContext;

            editContext.GridItems.Remove(b.DataContext);
            this.DataGrid.DataContext = null;
            this.DataGrid.DataContext = editContext;
        }
        private void Window_Loaded(object sender, RoutedEventArgs e)
        {
            GridEditorContext editContext = this.DataContext as GridEditorContext;

            Assert.ArgumentNotNull(editContext, nameof(editContext));
            this.DescriptionText.Text = editContext.Description;

            //Bind properties
            IEnumerable <PropertyInfo> propertiesToRender = editContext.ElementType.GetProperties().Where(prop => Attribute.IsDefined(prop, typeof(RenderInDataGreedAttribute)));

            foreach (var propertyToRender in propertiesToRender)
            {
                this.DataGrid.Columns.Add(new DataGridTextColumn()
                {
                    Binding = new Binding(propertyToRender.Name), Header = propertyToRender.Name
                });
            }
        }
        private void EditSolrs_Click(object sender, RoutedEventArgs e)
        {
            List <SolrDefinition> editCollection = new List <SolrDefinition>();

            foreach (var solr in this.Profile.Solrs)
            {
                editCollection.Add((SolrDefinition)solr.Clone());
            }

            GridEditorContext context = new GridEditorContext(typeof(SolrDefinition), editCollection, "List of available solr servers (Url+root+service name).");
            object            result  = WindowHelper.ShowDialog <GridEditor>(context, this);
            bool?dialogresult         = result as bool?;

            if ((result != null && dialogresult == null) || (dialogresult.HasValue && dialogresult.Value))
            {
                this.Profile.Solrs = context.GridItems.Cast <SolrDefinition>().ToList();
                this.RefreshSolrText();
            }
        }