SmartInfoPanel
A panel with a two-sided card at its left that turns over in 3D when it is clicked, beside content that stays put – a product photo that turns to show its specification, a contact's picture that turns to show their details, a figure that turns to show how it was reached.
public class SmartInfoPanel : ContentControl
Inherits from / implements: ContentControl
Remarks
The three pieces of content
RotatableContentFace– the side of the card on show at first.RotatableContentBack– the side shown once the card has turned.NonRotatableContent– shown to the right of the card, vertically centred, and never turned: a title, a price, a line saying "click the picture".
Each can be any element, or text. The panel's own ContentControl.Content is not
shown; use these three.
Turning the card
Pressing a mouse button on the card turns it over, in about a second, with the card dipping
away and coming back as it turns; pressing again turns it back. Flip does the same
from code, and IsFaceShowing says which side is up. RotateFlipType
chooses the movement: over the vertical or horizontal centre line, a spin in place, or a push in and
out. A button or other control on the card that handles its own clicks does not turn it.
While the card is at rest each side is shown as an ordinary flat element, so text stays sharp and controls on it work; the 3D picture is on screen only during the turn.
The turn is drawn on a square, so the card looks best when both sides are square and the same size – a 120 by 120 photo, say. The card takes the size of the larger side.
Appearance
The panel has a 1-pixel Control.BorderBrush outline in grey with rounded corners
(IsBorderEdgeCurved, BorderEdgeCornerRadius) and no
Control.Background. A soft glow can be put around the whole panel
(IsBorderDropShadowEnabled) and around the card
(IsRotatableContentDropShadowEnabled), and the 3D turn is lit by two lights
(DirectionalLightColor, AmbientLightColor).
Examples
A product tile in XAML. The assembly is Binarymission.WPF.Controls.SmartInfoPanel.
<Window x:Class="Shop.ProductWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:info="clr-namespace:Binarymission.WPF.Controls.Containers;assembly=Binarymission.WPF.Controls.SmartInfoPanel"
Title="Kettles" Width="520" Height="260">
<info:SmartInfoPanel x:Name="kettlePanel" Margin="16" Background="White"
RotateFlipType="FlipLeftToRight"
IsBorderDropShadowEnabled="True">
<info:SmartInfoPanel.RotatableContentFace>
<Image Source="/Images/Kettle.png" Width="120" Height="120" />
</info:SmartInfoPanel.RotatableContentFace>
<info:SmartInfoPanel.RotatableContentBack>
<Border Width="120" Height="120" Background="#F3F4F6" Padding="8">
<TextBlock TextWrapping="Wrap" Text="1.7 litres, 3 kW, brushed steel, rapid boil." />
</Border>
</info:SmartInfoPanel.RotatableContentBack>
<info:SmartInfoPanel.NonRotatableContent>
<StackPanel>
<TextBlock Text="Brushed steel kettle" FontSize="16" FontWeight="SemiBold" />
<TextBlock Text="£49.99" Margin="0,4,0,0" />
<TextBlock Text="Click the picture for the specification." Foreground="Gray" Margin="0,8,0,0" />
</StackPanel>
</info:SmartInfoPanel.NonRotatableContent>
</info:SmartInfoPanel>
</Window>Turning the card from code – here, back to its face when the next product is shown.
private void ShowProduct(Product product)
{
DataContext = product;
if (!kettlePanel.IsFaceShowing)
{
kettlePanel.Flip();
}
}See also
Members at a glance
| Properties | |
|---|---|
AmbientLightColor | Gets or sets the colour of the light that falls evenly on every part of the card while it turns, and so how bright the card stays when it is edge-on. |
BorderDropShadowColor | Gets or sets the colour of the glow around the whole panel. |
BorderDropShadowSoftness | Gets or sets how far the glow around the whole panel spreads. |
BorderEdgeCornerRadius | Gets or sets how rounded each corner of the panel's outline is. |
DirectionalLightColor | Gets or sets the colour of the light shining straight onto the card while it turns. |
IsBorderDropShadowEnabled | Gets or sets whether a soft glow is drawn around the whole panel, lifting it off the window. |
IsBorderEdgeCurved | Gets or sets whether the panel's outline has rounded corners. |
IsFaceShowing | Gets whether the face of the card – RotatableContentFace – is the side on show. |
IsRotatableContentDropShadowEnabled | Gets or sets whether a soft glow is drawn around the card. |
NonRotatableContent | Gets or sets the content shown to the right of the card, which stays still while the card turns – a name, a price, a short description. |
RotatableContentBack | Gets or sets the side of the card shown once it has been turned over. |
RotatableContentDropShadowColor | Gets or sets the colour of the glow around the card. |
RotatableContentDropShadowSoftness | Gets or sets how far the glow around the card spreads. |
RotatableContentFace | Gets or sets the side of the card on show at first, before it is turned. |
RotateFlipType | Gets or sets the movement the card makes as it turns over. |
| Methods | |
Flip | Turns the card over, exactly as a click on it does, using the current
RotateFlipType. |
OnApplyTemplate | Finds the parts of the template the panel works with, and puts on the glows and light colours. |
OnPreviewMouseDown | Gets the card's 3D surfaces ready before a click on the card turns it. |
| Fields | |
AmbientLightColorProperty | Identifies the AmbientLightColor dependency property. |
BorderDropShadowColorProperty | Identifies the BorderDropShadowColor dependency property. |
BorderDropShadowSoftnessProperty | Identifies the BorderDropShadowSoftness dependency property. |
BorderEdgeCornerRadiusProperty | Identifies the BorderEdgeCornerRadius dependency property. |
DirectionalLightColorProperty | Identifies the DirectionalLightColor dependency property. |
IsBorderDropShadowEnabledProperty | Identifies the IsBorderDropShadowEnabled dependency property. |
IsBorderEdgeCurvedProperty | Identifies the IsBorderEdgeCurved dependency property. |
IsRotatableContentDropShadowEnabledProperty | Identifies the IsRotatableContentDropShadowEnabled dependency property. |
NonRotatableContentProperty | Identifies the NonRotatableContent dependency property. |
RotatableContentBackProperty | Identifies the RotatableContentBack dependency property. |
RotatableContentDropShadowColorProperty | Identifies the RotatableContentDropShadowColor dependency property. |
RotatableContentDropShadowSoftnessProperty | Identifies the RotatableContentDropShadowSoftness dependency property. |
RotatableContentFaceProperty | Identifies the RotatableContentFace dependency property. |
RotateFlipTypeProperty | Identifies the RotateFlipType dependency property. |
Properties
AmbientLightColor
Gets or sets the colour of the light that falls evenly on every part of the card while it turns, and so how bright the card stays when it is edge-on.
- Value
- The control's style sets
#808080, a mid grey.
Remarks
Added channel by channel to DirectionalLightColor; see there.
BorderDropShadowColor
Gets or sets the colour of the glow around the whole panel.
- Value
- The control's style sets
Gray. The glow is drawn at 80% opacity.
See also
BorderDropShadowSoftness
Gets or sets how far the glow around the whole panel spreads.
- Value
- The blur radius in logical pixels (1/96 inch); the control's style sets 12. A negative value is taken as 0.
Remarks
Drawn only while IsBorderDropShadowEnabled is true, in
BorderDropShadowColor.
BorderEdgeCornerRadius
Gets or sets how rounded each corner of the panel's outline is.
- Value
- The radius of each corner – top left, top right, bottom right, bottom left – in
logical pixels (1/96 inch). The
control's style sets
4,4,9,9: slightly rounded at the top, more at the bottom.
Remarks
Used only while IsBorderEdgeCurved is true.
DirectionalLightColor
Gets or sets the colour of the light shining straight onto the card while it turns.
- Value
- The control's style sets
#808080, a mid grey.
Remarks
The lights matter only during the turn: at rest each side is shown flat, as it is.
The colours
of this light and AmbientLightColor are added together channel by channel,
and anything
above white is lost, so the two greys of the style add up to white and the turning card
looks as it
does at rest when it faces you.
To tint the turn, lower AmbientLightColor – to #303030, say –
and give this
light the colour.
IsBorderDropShadowEnabled
Gets or sets whether a soft glow is drawn around the whole panel, lifting it off the window.
- Value
trueto draw the glow; the default isfalse.
Remarks
The glow follows whatever the panel draws. Give the panel a
Control.Background so that it surrounds the panel's edge; with none, it falls on the
outline and on everything inside, text included.
See also
IsBorderEdgeCurved
Gets or sets whether the panel's outline has rounded corners.
- Value
truefor corners rounded byBorderEdgeCornerRadius;falsefor square corners whatever that radius. The control's style setstrue.
IsFaceShowing
Gets whether the face of the card – RotatableContentFace – is the side on show.
- Value
truewhile the face is up,falsewhile the back is. A panel whose template has not been built yet reportstrue.
Remarks
Turning away from the face, it becomes false as soon as the
turn starts;
turning back, it becomes true when the face reappears, about a second
later.
IsRotatableContentDropShadowEnabled
Gets or sets whether a soft glow is drawn around the card.
- Value
trueto draw the glow; the default isfalse.
Remarks
The glow follows the shape of what the card shows: a card with a solid background glows round its edge, while transparent parts let it fall on the content itself.
See also
NonRotatableContent
Gets or sets the content shown to the right of the card, which stays still while the card turns – a name, a price, a short description.
- Value
- Any element, or text. The default is
null: nothing beside the card.
Remarks
It is placed beside the card, vertically centred and aligned to the left.
RotatableContentBack
Gets or sets the side of the card shown once it has been turned over.
- Value
- Any element or text. The default is
null: the back of the card is empty.
Remarks
Make it the same size as RotatableContentFace; the card takes the
size of the
larger of the two.
See also
RotatableContentDropShadowColor
Gets or sets the colour of the glow around the card.
- Value
- The control's style sets
Gray. The glow is drawn at 80% opacity.
See also
RotatableContentDropShadowSoftness
Gets or sets how far the glow around the card spreads.
- Value
- The blur radius in logical pixels (1/96 inch); the control's style sets 12. A negative value is taken as 0.
Remarks
Drawn only while IsRotatableContentDropShadowEnabled is
true, in RotatableContentDropShadowColor.
RotatableContentFace
Gets or sets the side of the card on show at first, before it is turned.
- Value
- Any element – an
Image, aBorderwith text in it – or text. The default isnull: an empty card.
Remarks
Make it the same size as RotatableContentBack, and square if you
can: the turn
is drawn on a square.
See also
RotateFlipType
Gets or sets the movement the card makes as it turns over.
- Value
- The control's style sets
FlipType.FlipLeftToRight.
Remarks
Change it while the card is at rest: each movement is a template of its own, and the new one starts with its face up.
Example
<info:SmartInfoPanel RotateFlipType="StandardFlip" />Methods
Flip
Turns the card over, exactly as a click on it does, using the current
RotateFlipType.
Remarks
Turns from whichever side is up, so calling it twice brings the card back. Nothing happens before the panel's template has been built and laid out; call it once the window is loaded.
Example
// A "Details" button beside the panel turns the card over.
detailsButton.Click += (sender, e) => kettlePanel.Flip();See also
OnApplyTemplate
Finds the parts of the template the panel works with, and puts on the glows and light colours.
Remarks
A template of your own keeps the turning card only if it has a
ContentPresenter named fliprotatePresenter using one of the built-in flip
templates; the glows need elements named outerBorder and
rotatableContentPanel.
OnPreviewMouseDown
Gets the card's 3D surfaces ready before a click on the card turns it.
Parameters
e- The mouse event data, passed on unchanged.
Remarks
An override should call the base method, or the first click may turn a blank card.
Fields
AmbientLightColorProperty static
Identifies the AmbientLightColor dependency property.
BorderDropShadowColorProperty static
Identifies the BorderDropShadowColor dependency property.
BorderDropShadowSoftnessProperty static
Identifies the BorderDropShadowSoftness dependency property.
BorderEdgeCornerRadiusProperty static
Identifies the BorderEdgeCornerRadius dependency property.
DirectionalLightColorProperty static
Identifies the DirectionalLightColor dependency property.
IsBorderDropShadowEnabledProperty static
Identifies the IsBorderDropShadowEnabled dependency property.
IsBorderEdgeCurvedProperty static
Identifies the IsBorderEdgeCurved dependency property.
IsRotatableContentDropShadowEnabledProperty static
Identifies the IsRotatableContentDropShadowEnabled dependency property.
NonRotatableContentProperty static
Identifies the NonRotatableContent dependency property.
RotatableContentBackProperty static
Identifies the RotatableContentBack dependency property.
RotatableContentDropShadowColorProperty static
Identifies the RotatableContentDropShadowColor dependency property.
RotatableContentDropShadowSoftnessProperty static
Identifies the RotatableContentDropShadowSoftness dependency property.
RotatableContentFaceProperty static
Identifies the RotatableContentFace dependency property.
RotateFlipTypeProperty static
Identifies the RotateFlipType dependency property.