Class PropertySettingsAttribute
Attibute to specify a settings object for Properties and PropertyControls.
Inheritance
Implements
Inherited Members
Namespace: EPiServer.Core.PropertySettings
Assembly: EPiServer.dll
Version: 11.20.7Syntax
[AttributeUsage(AttributeTargets.Class)]
public sealed class PropertySettingsAttribute : Attribute, _Attribute
Remarks
Use this attibute to specify properties or property controls that need to store settings on the page definition level.
Examples
Simple example of marking a property control with a settings attibute:
[PropertySettings(typeof(SamplePropertySettings), true)]
public class SamplePropertyControlWithSettings : PropertyTextBoxControlBase
{
protected override void SetupEditControls()
{
EditControl.Text = ToString();
SamplePropertySettings settings = (SamplePropertySettings)PropertyData.GetSetting(typeof(SamplePropertySettings));
EditControl.Width = settings.Width;
}
}
You can then use it together with a EPiServer.Core.PropertySettings.PropertySettingsUIAttribute:
/// <summary>
/// Used to render a UI for editing the settings in the admin UI.
/// Needs to be in the inherit from <see cref="Control"/> and implement <see cref="IPropertySettingsUI"/>.
/// Most easily accomplished using <see cref="PropertySettingsUIBase"/>
/// </summary>
public class SettingsUISample : PropertySettingsControlBase
{
private TextBox _widthInput;
#region IPropertySettingsUI Members
protected override void CreateChildControls()
{
base.CreateChildControls();
_widthInput = new TextBox { ID = "WidthValue" };
Label label = new Label { Text = "Width", AssociatedControlID = "WidthValue" };
Controls.Add(label);
Controls.Add(_widthInput);
}
public override void LoadSettingsUI(IPropertySettings propertySettings)
{
EnsureChildControls();
_widthInput.Text = ((SamplePropertySettings)propertySettings).Width.ToString();
}
public override void UpdateSettings(IPropertySettings propertySettings)
{
EnsureChildControls();
((SamplePropertySettings)propertySettings).Width = int.Parse(_widthInput.Text);
}
#endregion
}
Constructors
PropertySettingsAttribute(Type)
Initializes a new instance of the PropertySettingsAttribute class.
Declaration
public PropertySettingsAttribute(Type settingsType)
Parameters
Type | Name | Description |
---|---|---|
System.Type | settingsType | Type of settings entity to use. |
PropertySettingsAttribute(Type, Boolean)
Initializes a new instance of the PropertySettingsAttribute class.
Declaration
public PropertySettingsAttribute(Type settingsType, bool useGlobals)
Parameters
Type | Name | Description |
---|---|---|
System.Type | settingsType | Type of settings entity to use. |
System.Boolean | useGlobals | if set to |
Properties
SettingsType
Gets or sets the type of settings entity.
Declaration
public Type SettingsType { get; set; }
Property Value
Type | Description |
---|---|
System.Type | The type of the settings. |
UseGlobals
Gets or sets a value indicating whether to enable multiple global settings to choose from in the admin UI.
Declaration
public bool UseGlobals { get; set; }
Property Value
Type | Description |
---|---|
System.Boolean |
|
Methods
TryGetAttribute(Type, out PropertySettingsAttribute)
Tries to get a PropertySettingsAttribute from a type.
Declaration
public static bool TryGetAttribute(Type type, out PropertySettingsAttribute attribute)
Parameters
Type | Name | Description |
---|---|---|
System.Type | type | The type. |
PropertySettingsAttribute | attribute | The attribute to set if succesfull. |
Returns
Type | Description |
---|---|
System.Boolean |
|