APPENDIX C

image

Using Properties in Custom Controls

When you create a custom Silverlight control extension, you can bind the attributes of user-interface (UI) elements to the values that a developer enters in the Visual Studio screen designer (Figure C-1).

9781484207673_Fig26-01.jpg

Figure C-1. Property values that developers can modify

Chapter 19 (Listing 19-7) included a custom control that binds to values from the property sheet. An excerpt of this code is shown in Listing C-1.

The data-binding syntax in this code includes the property names Width, Height, TextAlignment, and VerticalAlignment. You can use these property names in your XAML and .NET code. The purpose of this appendix is to show you a list of property names that you can use in your code.

The appearance properties that are shown next are “opt-out” properties. This refers to properties that LightSwitch automatically shows in the property sheet:

  • AttachedLabelPosition
  • HeightSizingMode
  • WidthSizingMode
  • MinHeight
  • MaxHeight
  • MinWidth
  • MaxWidth
  • Height
  • Width
  • Rows
  • Characters
  • VerticalAlignment
  • HorizontalAlignment

The other group of property names that you can refer to are “opt-in” properties. By default, these properties don’t show up in Visual Studio’s properties sheet. To make them appear, you need to set the property’s EditorVisibility value to PropertySheet in your custom control’s LSML file, as shown in Listing C-2. Refer to Chapter 19 (Listing 19-23) to see a full example of a custom control’s LSML file.

The two EditorVisibility values that you can set are the following:

  • NotDisplayed
  • PropertySheet

Here’s a full list of opt-in properties that you can use:

  • ShowAsLink
  • FontStyle
  • TextAlignment
  • BrowseOnly
  • Image

To see a built-in control that implements two of these opt-in properties, take a look at the label control. If you add a label control to a screen and open the properties sheet, you can find options to set the ShowAsLink and FontStyle properties.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset