|
Raster Graphics : Saving to the Picture Library |
In your program, you create an instance of the MediaLibrary class. The SavedPictures property returns a PictureCollection with a Picture object for each item currently in the Saved Pictures album. |
|
Raster Graphics : Images and Tombstoning |
A Windows version appeared in early versions of the Microsoft Windows Software Development Kit (SDK) under the name MUZZLE, where it was the only sample program in the SDK coded in Microsoft Pascal rather than C. |
|
Raster Graphics : Vector Graphics on a Bitmap |
You can combine the two approaches of drawing on a WriteableBitmap. The next sample displays a Path on a WriteableBitmap against a gradient that uses transparency so that you can see how the premultiplied alphas work. |
|
Raster Graphics : The Pixel Bits |
The Pixels property of WritableBitmap is an array of int, which means that each pixel is 32 bits wide. The Pixels property itself is get-only so you can’t replace the actual array, but you can set and get elements of that array. |
|
Raster Graphics : WriteableBitmap and UIElement |
The element argument is of type UIElement and the transform argument is of type Transform. This constructor creates a bitmap based on the size of the UIElement argument as possibly modified by the Transform argument |
|
|
Vector Graphics : The Path Markup Syntax |
Silverlight supports a type of “mini-language” that allows you to encode an entire PathGeometry in a string. The language consists of letters (such as M for Move, L for Line, A for Arc, and C for Cubic Bézier) that take the place of PathFigure and PathSegment objects |
|
Vector Graphics : Bézier Curves |
The Bézier curve is a spline, which is a type of curve used to approximate discrete data with a smooth continuous function. Silverlight supports the standard two-dimensional form of the cubic Bézier curve but also a quadratic Bézier curve that is somewhat simpler and faster. |
|
Vector Graphics : The Versatile PathGeometry |
LineGeometry, RectangleGeometry, EllipseGeometry, GeometryGroup—those are all convenient special cases of PathGeometry, certainly the most versatile of the Geometry derivatives. |
|
|
|
Vector Graphics : The Path Element |
The Path class defines just one property of its own named Data of type Geometry, but geometries are a very important concept in Silverlight vector graphics |
|
Vector Graphics : Dynamic Polygons |
Certain collections will also respond to changes. Collection classes that derive from PresentationFrameworkCollection respond to changes when an object is added to or removed from a collection |
|
Vector Graphics : The Stretch Property |
You can probably see why the Stretch property of Shape isn’t used very often in connection with vector graphics, but if you need a particular vector image to fill an area of arbitrary size, it’s a welcome option. |
|
Vector Graphics : Polygon and Fill |
If you want the figure to be really closed, you can add another point to the Points collection that is the same as the first point, or you can use a Polygon rather than a Polyline |
|
|
|
Vector Graphics : Overlapping and ZIndex |
If you would prefer that the blue line be on top of the red line, there are two ways you can do it. You could simply swap the order of the two lines in the Grid |
|
Vector Graphics : Canvas and Grid |
Coordinates can be negative, but the Grid does not take account of negative coordinates. A negative coordinate will actually be displayed to the left of or above the Grid. |
|
Vector Graphics : The Shapes Library |
A Silverlight program that needs to draw vector graphics uses classes defined in the System.Windows.Shapes namespace, commonly referred to as the Shapes library. |
|
Data Bindings : TextBox Binding Updates |
The Text property of a TextBox can be a target of a data binding, but some potential problems are introduced. Once you allow the user to type anything into a TextBox, you need to deal with faulty input. |
|
Data Bindings : Give and Take |
The two binding services you’ve seen so far simply provide information. You can also create bindings in XAML that deliver data to the binding service and get back a result. |
|
|
Data Bindings : Simple Decision Making |
Normally you can do that by formatting the time (if the Clock class actually provided a DateTime object indicating the time) but suppose you want to be very flexible about how you display the AM and PM information—perhaps you’d prefer to display the text “in the morning” or “in the afternoon”—and you want to do it in XAML. |
|
Data Bindings : Setting the DataContext |
FrameworkElement defines a property named DataContext that you can set to pretty much any object (in code) or generally a binding (in XAML). The DataContext is one of those properties that propagates down through the visual tree, at which point it can be combined with more local bindings. |
|
Data Bindings : A Simple Binding Server |
For example, suppose you want to display the current time in a Windows Phone 7 application, and you want to be fairly flexible about what you display. Perhaps sometimes you only want to display seconds, and you want to do this entirely in XAML. |
|
Data Bindings : Notification Mechanisms |
For data bindings to work, the binding source must implement some kind of notification mechanism. This notification mechanism signals when the property value has changed so the new value can be retrieved from the source and transferred to the target. |
|
Data Bindings - The “this” Source |
BorderedText derives from UserControl, and UserControl derives from Control, so we know that BorderedText will already have some of these properties through class inheritance. |
|
Data Bindings - Relative Source |
The third type of binding is called RelativeSource. In the Windows Presentation Foundation, RelativeSource is much more flexible than the version in Silverlight, so you may not be very impressed with this option. |
|
Data Bindings - Binding Converters |
The Converter property of the Binding class is of type IValueConverter, an interface that requires only two methods named Convert and ConvertBack. |
|
Data Bindings : Target and Mode |
Bindings have a source and a target. The binding target is considered to be the property on which the binding is set. This property must always be backed by a dependency property |
|
|
Dependency Properties - Attached Properties |
Notice that the first argument to the PropertyMetadata constructor is explicitly a double so there won’t be a runtime error because the C# compiler assumes the value is an int. |
|
Dependency Properties - Panels with Properties |
The Windows Presentation Foundation has a panel I often find useful called UniformGrid. As the name suggests, the UniformGrid divides its area into cells, each of which has the same dimensions. |
|
Dependency Properties - A New Type of Toggle |
If you experiment with these controls a bit, you’ll find that you can toggle the switch just by tapping it, but you can also move the larger block back and forth with your finger, although it will tend to snap into position either at the left or right. |
|
Dependency Properties - Deriving from UserControl |
Deriving from Control or ContentControl in a proper and cordial manner involves creating a default template in XAML that describes the control’s visual appearance, and allowing that template to be replaced to redefine the visuals of the control. |
|
Dependency Properties - The Dependency Property Difference |
What Silverlight providesis an infrastructure to manage all the different ways properties can be set and to impose some kind of order. Dependency properties are a major part of this infrastructure. They’re called dependency properties because the properties depend on a bunch of different external forces, which are then mediated. |
|
Dependency Properties - The Problem Illustrated |
Suppose you want to use a bunch of buttons whose foregrounds are colored with various linear gradient brushes, and you figure it would be convenient for you to specify the two colors as properties of the buttons, perhaps properties named Color1 and Color2. |
|
The App Bar and Controls - TextBox and Keyboard Input |
The two types of text-entry controls available in Silverlight for Windows Phone are TextBox, which allows typing and editing single-line or multiline plain unformatted text, and PasswordBox, which briefly displays each letter you type but then replaces it with another character, by default an asterisk. |
|
The App Bar and Controls - Buttons and Styles |
As a general rule, it makes sense to set TargetType to be the most general class that has all the properties you’re defining in the Style. You can inherit from styles based on derived classes. |
|
|
The App Bar and Controls - The Button Hierarchy |
Normally the ToggleButton and CheckBox are physical manifestations of a Boolean. They turn on and off with successive clicks. But ToggleButton defines an IsThreeState property that optionally provides a third “indeterminate” state |
|
|
|
The App Bar and Controls - The Basic Button |
It has a simple white border and displays the text string assigned to its Content property. If you put the Button in a horizontal StackPanel, it will be only as wide as it needs to be to fit the content; the opposite effect happens when you switch the StackPanel orientation to Vertical. |
|
The App Bar and Controls - RangeBase and Slider |
The RangeBase class defines Minimum, Maximum, SmallChange, and LargeChange properties to define the parameters of scrolling, plus a Value property for the user’s selection and a ValueChanged event that signals when Value has changed. |
|
The App Bar and Controls - Elements and Controls |
These derivatives of FrameworkElement include TextBlock, Image, Border, MediaElement, Shape (which is the parent class to Rectangle and Ellipse), and Panel, which is the parent class to Grid, StackPanel, and Canvas. |
|
|
The App Bar and Controls - Jot and Touch |
When the finger first touches the screen (signaled by an Action property of TouchAction.Down), the method creates a new Stroke object. This is added to the Strokes collection of the InkPresenter, and it is re-rendered by InkPresenter with each new point added to it. |
|