Logo
programming4us
programming4us
programming4us
programming4us
Home
programming4us
XP
programming4us
Windows Vista
programming4us
Windows 7
programming4us
Windows Azure
programming4us
Windows Server
programming4us
Windows Phone
 
Windows Phone

Windows Phone 7 : The Silverlight Controls (part 5) - Interactive Controls - CheckBox Controls, RadioButton Controls

- Free product key for windows 10
- Free Product Key for Microsoft office 365
- Malwarebytes Premium 3.7.1 Serial Keys (LifeTime) 2019
1/20/2014 2:00:51 AM
2.4. CheckBox Controls

A simple but useful control, the CheckBox allows simple boolean values to be gathered from the user. When the control's value is true, it displays a check mark within the control; when it is false, the box is shown empty.

The caption displayed next to the CheckBox is part of the control itself rather than being implemented as a separate control, so tapping on either the actual displayed box or its caption will cause the state of the box to be toggled.

The caption is provided using the CheckBox control's Content property, and is not limited to being just a simple string: other controls can be placed into the content to provide additional formatting options.

A few useful properties that we might want to use are offered by the control. Among them are the IsChecked property, which allows the initial state of the CheckBox to be set (and which can, of course, also be set or queried in code to update or read the state of the control).

Another potentially useful property is the IsThreeState property. When this property is set to true, the CheckBox will cycle through three different states when it is tapped: checked, unchecked, and indeterminate. This final state can be used when the CheckBox is at an unknown state or when its value cannot currently be represented as a simple boolean value. When the control's value is indeterminate, the IsChecked property in code will return null. To set this in XAML, the special value {x:Null} must be provided for the property (though this can be picked from the Properties window).

Listing 8 shows the XAML for three CheckBox controls, each with a different initial state.

Example 8. Several CheckBox controls
<CheckBox Height="70" Width="215" Margin="50,100" VerticalAlignment="Top"
Content="Unchecked" />
<CheckBox Height="70" Width="215" Margin="50,160" VerticalAlignment="Top"
Content="Checked" IsChecked="True" />
<CheckBox Height="70" Width="215" Margin="50,220" VerticalAlignment="Top"
Content="Indeterminate" IsChecked="{x:Null}" />


The resulting controls are shown in Figure 10.

Figure 10. The resulting CheckBox controls

The CheckBox offers two different ways of responding to its state changing. The first is to add a handler for its Click event that will fire every time the control is tapped by the user, allowing the IsChecked property to be queried to determine the control's new value.

Alternatively. you might add handlers to any or all of the Checked, Unchecked, or Indeterminate events. These handlers will fire when the CheckBox is updated to the corresponding state. If they are used as well as the Click event, the Click event will fire after the approriate state-based event.

NOTE

A useful feature of the Checked, Unchecked, and Indeterminate events is that they fire when the page first loads, allowing for any initial processing that is required based on the CheckBox state to be performed. The Click event only fires when the user actually interacts with the control.

2.5. RadioButton Controls

RadioButton controls offer similar functionality to the CheckBox, except that they are formed into mutually exclusive groups from which only a single RadioButton at a time can be selected. The properties and events used by the RadioButton are virtually identical to those of the CheckBox.

An additional property, called GroupName, is available, however. It is not set by default, and will result in the radio buttons being set as a group according to the container that they are placed in (only one of the radio buttons in the container can be selected). In many cases, this will be the desirable behavior, but if you want to have radio buttons that span across multiple containers or if you want to create separate groups of radio buttons within the same container, set the GroupName to a consistent value for all the controls within each group. Silverlight will look after everything else.

2.6. Button Controls

The next of the interactive controls that we will look at is also one of the simplest. Button controls simply display some content within a rectangular frame on the screen and respond to being clicked by raising their Click event.

The Button's text is specified within its Content property, but once again the property is not limited only to strings. Other UI elements can be placed within the button to facilitate buttons with images or other content.

Other -----------------
- Windows Phone 7 : The Silverlight Controls (part 1) - Display Controls -TextBlock Controls, Image Controls, ProgressBar Controls
- Windows Phone 8 : Using Sound (part 2) - Recording Sounds
- Windows Phone 8 : Using Sound (part 1) - Playing Sounds with MediaElement, Using XNA Libraries, Playing Sounds with XNA, Adjusting Playback
- Windows Phone 8 : Localizing Your Phone Application
- Windows Phone 7 : Running Silverlight Projects in the Browser (part 2)
- Windows Phone 7 : Running Silverlight Projects in the Browser (part 1)
- Windows Phone 7 : Running XNA Projects in Windows (part 5)
- Windows Phone 7 : Running XNA Projects in Windows (part 4) - Converting the Game Framework to Run on Windows
- Windows Phone 7 : Running XNA Projects in Windows (part 3) - Input Differences, Isolated Storage, Application Life Cycle
- Windows Phone 7 : Running XNA Projects in Windows (part 2) - Display Differences
 
 
Top 10
- Microsoft Visio 2013 : Adding Structure to Your Diagrams - Finding containers and lists in Visio (part 2) - Wireframes,Legends
- Microsoft Visio 2013 : Adding Structure to Your Diagrams - Finding containers and lists in Visio (part 1) - Swimlanes
- Microsoft Visio 2013 : Adding Structure to Your Diagrams - Formatting and sizing lists
- Microsoft Visio 2013 : Adding Structure to Your Diagrams - Adding shapes to lists
- Microsoft Visio 2013 : Adding Structure to Your Diagrams - Sizing containers
- Microsoft Access 2010 : Control Properties and Why to Use Them (part 3) - The Other Properties of a Control
- Microsoft Access 2010 : Control Properties and Why to Use Them (part 2) - The Data Properties of a Control
- Microsoft Access 2010 : Control Properties and Why to Use Them (part 1) - The Format Properties of a Control
- Microsoft Access 2010 : Form Properties and Why Should You Use Them - Working with the Properties Window
- Microsoft Visio 2013 : Using the Organization Chart Wizard with new data
 
programming4us
Windows Vista
programming4us
Windows 7
programming4us
Windows Azure
programming4us
Windows Server