public override FrameworkElement CreateControl(PropertyItem pi, PropertyControlFactoryOptions options) { // Check if the property is of type Range if (pi.Is(typeof(Range))) { // Create a control to edit the Range return(this.CreateRangeControl(pi, options)); } return(base.CreateControl(pi, options)); }
public override FrameworkElement CreateControl(PropertyItem pi, PropertyControlFactoryOptions options) { //if (property.Is(typeof(DateTime))) //{ // var dp = new DatePicker() { SelectedDateFormat = DatePickerFormat.Long, DisplayDateStart = DateTime.Now.AddDays(-7) }; // dp.SetBinding(DatePicker.SelectedDateProperty, // new Binding(property.Descriptor.Name) { ValidatesOnDataErrors = true }); // return dp; //} return(base.CreateControl(pi, options)); }
public override FrameworkElement CreateControl(PropertyItem property, PropertyControlFactoryOptions options) { if (typeof(ICommand).IsAssignableFrom(property.ActualPropertyType)) { property.HeaderPlacement = HeaderPlacement.Hidden; var result = new Button { Content = property.DisplayName }; result.SetBinding(ButtonBase.CommandProperty, property.CreateBinding()); return(result); } return(base.CreateControl(property, options)); }
public override FrameworkElement CreateControl(PropertyItem pi, PropertyControlFactoryOptions options) { if ((pi.ItemsSourceDescriptor != null) || (pi.ItemsSource != null)) { return(this.CreateComboBoxControl(pi)); } if (pi.Is(typeof(Collection <string>))) { return(this.CreateListControl(pi)); } if (pi.Is(typeof(ICommand))) { return(this.CreateCommandControl(pi)); } return(base.CreateControl(pi, options)); }
public override FrameworkElement CreateControl(PropertyItem pi, PropertyControlFactoryOptions options) { FrameworkElement retval = null; if (pi.Is(typeof(CommandProperty))) { pi.HeaderPlacement = HeaderPlacement.Collapsed; retval = CreateCommandLinkControl(pi); } else if (pi.GetAttribute <NestedPropertiesAttribute>() != null) { if (pi.Is(typeof(ICollection)) || pi.Is(typeof(ICollection <>))) { retval = CreateNestedPropertyGridsControl(pi); } else { retval = CreateNestedPropertyGridControl(pi); } } else { var rla = pi.GetAttribute <ReferenceLookupAttribute>(); if (rla != null) { if (pi.Is(typeof(string))) { pi.Converter = new ReferenceListLookupConverter { LookupKey = rla.LookupKey }; pi.ItemsSource = ReferenceLookupList.GetCompleteList(rla.LookupKey); retval = this.CreateBindableComboBoxControl(pi, rla.LookupKey); } else if (pi.Is(typeof(IEnumerable))) { pi.Converter = new ReferenceListLookupConverter { LookupKey = rla.LookupKey }; pi.ItemsSource = ReferenceLookupList.GetCompleteList(rla.LookupKey); retval = this.CreateBindableMultipleSelectControl(pi, rla.LookupKey); } else { pi.Converter = new ReferenceLookupConverter { LookupKey = rla.LookupKey }; retval = base.CreateDefaultControl(pi); } } else { retval = base.CreateControl(pi, options); } } retval.Name = pi.Descriptor.Name + "PropertyPageElem"; return(retval); }
public override ContentControl CreateErrorControl(PropertyItem pi, object instance, Tab tab, PropertyControlFactoryOptions options) { if (options == null) { throw new ArgumentNullException(nameof(options), "options was null."); } if (pi == null) { throw new ArgumentNullException(nameof(pi), "pi was null."); } INotifyDataErrorInfo notifyDataErrorInfoInstance = (INotifyDataErrorInfo)instance; // Overrides the default error template. Resource can be found in App.xaml. if (Application.Current.TryFindResource("PropertyGridValidationTemplate") != null) { options.ValidationErrorTemplate = (DataTemplate)Application.Current.TryFindResource("PropertyGridValidationTemplate"); } ContentControl errorControl = new() { ContentTemplate = options.ValidationErrorTemplate, Focusable = false }; IValueConverter errorConverter; string propertyPath; // CustomNotifyDataErrorInfoConverter being used instead of the default in PropertyGrid; NotifyDataErrorInfoConverter errorConverter = new CustomNotifyDataErrorInfoConverter(notifyDataErrorInfoInstance !, pi.PropertyName); propertyPath = nameof(tab.HasErrors); if (notifyDataErrorInfoInstance != null) { notifyDataErrorInfoInstance.ErrorsChanged += (s, e) => { UpdateTabForValidationResults(tab, notifyDataErrorInfoInstance); // Refresh bindings for Content and Visibility. errorControl.GetBindingExpression(ContentControl.ContentProperty).UpdateTarget(); errorControl.GetBindingExpression(UIElement.VisibilityProperty).UpdateTarget(); }; } Binding visibilityBinding = new(propertyPath) { Converter = errorConverter, NotifyOnTargetUpdated = true, ValidatesOnNotifyDataErrors = false, Source = tab }; Binding contentBinding = new(propertyPath) { Converter = errorConverter, ValidatesOnNotifyDataErrors = false, Source = tab }; errorControl.SetBinding(UIElement.VisibilityProperty, visibilityBinding); errorControl.SetBinding(ContentControl.ContentProperty, contentBinding); return(errorControl); } } }
/// <inheritdoc /> public override ContentControl CreateErrorControl(PropertyItem pi, object instance, Tab tab, PropertyControlFactoryOptions options) { var dataErrorInfoInstance = instance as IDataErrorInfo; var notifyDataErrorInfoInstance = instance as INotifyDataErrorInfo; if (Application.Current.TryFindResource("ValidationErrorTemplateEx") != null) { options.ValidationErrorTemplate = (DataTemplate)Application.Current.TryFindResource("ValidationErrorTemplateEx"); } var errorControl = new ContentControl { ContentTemplate = options.ValidationErrorTemplate, Focusable = false }; IValueConverter errorConverter; string propertyPath; object source = null; if (dataErrorInfoInstance != null) { errorConverter = new DataErrorInfoConverter(dataErrorInfoInstance, pi.PropertyName); propertyPath = pi.PropertyName; source = instance; } else { errorConverter = new NotifyDataErrorInfoConverter(notifyDataErrorInfoInstance, pi.PropertyName); propertyPath = nameof(tab.HasErrors); source = tab; notifyDataErrorInfoInstance.ErrorsChanged += (s, e) => { UpdateTabForValidationResults(tab, notifyDataErrorInfoInstance); //needed to refresh error control's binding also when error changes (i.e from Error to Warning) errorControl.GetBindingExpression(ContentControl.ContentProperty).UpdateTarget(); }; } var visibilityBinding = new Binding(propertyPath) { Converter = errorConverter, NotifyOnTargetUpdated = true, #if !NET40 ValidatesOnNotifyDataErrors = false, #endif Source = source, }; var contentBinding = new Binding(propertyPath) { Converter = errorConverter, #if !NET40 ValidatesOnNotifyDataErrors = false, #endif Source = source, }; var warningBinding = new Binding(nameof(tab.HasWarnings)) { Converter = errorConverter, #if !NET40 ValidatesOnNotifyDataErrors = false, #endif Source = source, }; errorControl.SetBinding(UIElement.VisibilityProperty, visibilityBinding); // When the visibility of the error control is changed, updated the HasErrors of the tab errorControl.TargetUpdated += (s, e) => { if (dataErrorInfoInstance != null) { tab.UpdateHasErrors(dataErrorInfoInstance); } }; errorControl.SetBinding(ContentControl.ContentProperty, contentBinding); errorControl.SetBinding(ContentControl.ContentProperty, warningBinding); return(errorControl); }