public virtual PropertyViewModel CreateViewModel(object instance, PropertyDescriptor descriptor) { PropertyDescriptorCollection pdc = TypeDescriptor.GetProperties(instance); PropertyViewModel propertyViewModel = null; string optionalPropertyName; if (IsOptional(descriptor, out optionalPropertyName)) { propertyViewModel = new OptionalPropertyViewModel(instance, descriptor, optionalPropertyName, owner); } if (IsPassword(descriptor)) { propertyViewModel = new PasswordPropertyViewModel(instance, descriptor, owner); } if (IsResettable(descriptor)) { propertyViewModel = new ResettablePropertyViewModel(instance, descriptor, owner); } if (UsePropertyPattern != null) { string usePropertyName = String.Format(UsePropertyPattern, descriptor.Name); PropertyDescriptor useDescriptor = pdc.Find(usePropertyName, false); if (useDescriptor != null) { propertyViewModel = new OptionalPropertyViewModel(instance, descriptor, useDescriptor, owner); } } bool showHeader; if (IsWide(descriptor, out showHeader)) { propertyViewModel = new WidePropertyViewModel(instance, descriptor, showHeader, owner); } // If bool properties should be shown as checkbox only (no header label), we create a CheckBoxPropertyViewModel if (descriptor.PropertyType == typeof(bool) && owner != null && !owner.ShowBoolHeader) { propertyViewModel = new CheckBoxPropertyViewModel(instance, descriptor, owner); } double min, max, largeChange, smallChange; double tickFrequency; bool snapToTicks; TickPlacement tickPlacement; if (IsSlidable(descriptor, out min, out max, out largeChange, out smallChange, out tickFrequency, out snapToTicks, out tickPlacement)) { propertyViewModel = new SlidablePropertyViewModel(instance, descriptor, owner) { SliderMinimum = min, SliderMaximum = max, SliderLargeChange = largeChange, SliderSmallChange = smallChange, SliderSnapToTicks = snapToTicks, SliderTickFrequency = tickFrequency, SliderTickPlacement = tickPlacement } } ; // FilePath string filter, defaultExtension; bool useOpenDialog; if (IsFilePath(descriptor, out filter, out defaultExtension, out useOpenDialog)) { propertyViewModel = new FilePathPropertyViewModel(instance, descriptor, owner) { Filter = filter, DefaultExtension = defaultExtension, UseOpenDialog = useOpenDialog } } ; // DirectoryPath if (IsDirectoryPath(descriptor)) { propertyViewModel = new DirectoryPathPropertyViewModel(instance, descriptor, owner); } // Default property (using textbox) if (propertyViewModel == null) { var tp = new PropertyViewModel(instance, descriptor, owner); propertyViewModel = tp; } // Check if the AutoUpdatingText attribute is set (this will select the template that has a text binding using UpdateSourceTrigger=PropertyChanged) if (IsAutoUpdatingText(descriptor)) { propertyViewModel.AutoUpdateText = true; } propertyViewModel.FormatString = GetFormatString(descriptor); //var ha = AttributeHelper.GetFirstAttribute<HeightAttribute>(descriptor); //if (ha != null) // propertyViewModel.Height = ha.Height; propertyViewModel.Height = GetHeight(descriptor); propertyViewModel.MaxLength = GetMaxLength(descriptor); if (propertyViewModel.Height > 0 || IsMultilineText(descriptor)) { propertyViewModel.AcceptsReturn = true; propertyViewModel.TextWrapping = TextWrapping.Wrap; } var soa = AttributeHelper.GetFirstAttribute <SortOrderAttribute>(descriptor); if (soa != null) { propertyViewModel.SortOrder = soa.SortOrder; } if (IsEnabledPattern != null) { string isEnabledName = String.Format(IsEnabledPattern, descriptor.Name); propertyViewModel.IsEnabledDescriptor = pdc.Find(isEnabledName, false); } if (IsVisiblePattern != null) { string isVisibleName = String.Format(IsVisiblePattern, descriptor.Name); propertyViewModel.IsVisibleDescriptor = pdc.Find(isVisibleName, false); } return(propertyViewModel); }
public virtual PropertyViewModel CreateViewModel(object instance, PropertyDescriptor descriptor) { PropertyDescriptorCollection pdc = TypeDescriptor.GetProperties(instance); PropertyViewModel propertyViewModel = null; string optionalPropertyName; if (IsOptional(descriptor, out optionalPropertyName)) propertyViewModel = new OptionalPropertyViewModel(instance, descriptor, optionalPropertyName, owner); if (IsPassword(descriptor)) propertyViewModel = new PasswordPropertyViewModel(instance, descriptor, owner); if (IsResettable(descriptor)) propertyViewModel = new ResettablePropertyViewModel(instance, descriptor, owner); if (UsePropertyPattern != null) { string usePropertyName = String.Format(UsePropertyPattern, descriptor.Name); PropertyDescriptor useDescriptor = pdc.Find(usePropertyName, false); if (useDescriptor != null) propertyViewModel = new OptionalPropertyViewModel(instance, descriptor, useDescriptor, owner); } bool showHeader; if (IsWide(descriptor, out showHeader)) propertyViewModel = new WidePropertyViewModel(instance, descriptor, showHeader, owner); // If bool properties should be shown as checkbox only (no header label), we create a CheckBoxPropertyViewModel if (descriptor.PropertyType == typeof(bool) && owner != null && !owner.ShowBoolHeader) propertyViewModel = new CheckBoxPropertyViewModel(instance, descriptor, owner); double min, max, largeChange, smallChange; double tickFrequency; bool snapToTicks; TickPlacement tickPlacement; if (IsSlidable(descriptor, out min, out max, out largeChange, out smallChange, out tickFrequency, out snapToTicks, out tickPlacement)) propertyViewModel = new SlidablePropertyViewModel(instance, descriptor, owner) { SliderMinimum = min, SliderMaximum = max, SliderLargeChange = largeChange, SliderSmallChange = smallChange, SliderSnapToTicks = snapToTicks, SliderTickFrequency = tickFrequency, SliderTickPlacement = tickPlacement }; // FilePath string filter, defaultExtension; bool useOpenDialog; if (IsFilePath(descriptor, out filter, out defaultExtension, out useOpenDialog)) propertyViewModel = new FilePathPropertyViewModel(instance, descriptor, owner) { Filter = filter, DefaultExtension = defaultExtension, UseOpenDialog = useOpenDialog }; // DirectoryPath if (IsDirectoryPath(descriptor)) propertyViewModel = new DirectoryPathPropertyViewModel(instance, descriptor, owner); // Default property (using textbox) if (propertyViewModel == null) { var tp = new PropertyViewModel(instance, descriptor, owner); propertyViewModel = tp; } // Check if the AutoUpdatingText attribute is set (this will select the template that has a text binding using UpdateSourceTrigger=PropertyChanged) if (IsAutoUpdatingText(descriptor)) propertyViewModel.AutoUpdateText = true; propertyViewModel.FormatString = GetFormatString(descriptor); //var ha = AttributeHelper.GetFirstAttribute<HeightAttribute>(descriptor); //if (ha != null) // propertyViewModel.Height = ha.Height; propertyViewModel.Height = GetHeight(descriptor); propertyViewModel.MaxLength = GetMaxLength(descriptor); if (propertyViewModel.Height > 0 || IsMultilineText(descriptor)) { propertyViewModel.AcceptsReturn = true; propertyViewModel.TextWrapping = TextWrapping.Wrap; } var soa = AttributeHelper.GetFirstAttribute<SortOrderAttribute>(descriptor); if (soa != null) propertyViewModel.SortOrder = soa.SortOrder; if (IsEnabledPattern != null) { string isEnabledName = String.Format(IsEnabledPattern, descriptor.Name); propertyViewModel.IsEnabledDescriptor = pdc.Find(isEnabledName, false); } if (IsVisiblePattern != null) { string isVisibleName = String.Format(IsVisiblePattern, descriptor.Name); propertyViewModel.IsVisibleDescriptor = pdc.Find(isVisibleName, false); } return propertyViewModel; }