1 <Page x:Class="SamplePage"
2 xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
3 xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
4 xmlns:my="clr-namespace:Postcard3D"
5 Title="Postcard3D" Background="{StaticResource GoldenBrownGradient}">
6 <Viewbox Margin="0,20,0,0">
10 <RowDefinition MinHeight="440"/>
11 </Grid.RowDefinitions>
13 <Grid.ColumnDefinitions>
16 </Grid.ColumnDefinitions>
18 <!-- High Contrast InkCanvas for rendering ink onto the photo -->
19 <my:HighContrastInkCanvas x:Name="icFront" Grid.Column="0" Width="400" Height="300" >
20 <Grid Width="{Binding ElementName=icFront,Path=Width}" Height="{Binding ElementName=icFront,Path=Height}">
21 <Border BorderBrush="White" BorderThickness="5" >
22 <Image Source="seattle_rainier.jpg"/>
25 </my:HighContrastInkCanvas>
27 <!-- Regular InkCanvas for rendering ink onto the backside of the postcard -->
28 <InkCanvas Name="icBack" Grid.Column="1"
29 Width="{Binding ElementName=icFront,Path=Width}"
30 Height="{Binding ElementName=icFront,Path=Height}">
31 <InkCanvas.DefaultDrawingAttributes>
32 <DrawingAttributes Color="Blue" Width="1" Height="1"/>
33 </InkCanvas.DefaultDrawingAttributes>
34 <Border BorderBrush="LightGray" BorderThickness="2"
35 Width="{Binding ElementName=icBack,Path=Width}"
36 Height="{Binding ElementName=icBack,Path=Height}">
37 <Grid Background="WhiteSmoke" >
38 <Grid.ColumnDefinitions>
39 <ColumnDefinition Width="*"/>
40 <ColumnDefinition Width="*"/>
41 </Grid.ColumnDefinitions>
43 <RowDefinition Height="100"/>
45 </Grid.RowDefinitions>
46 <Image HorizontalAlignment="Right" Margin="10,10" Grid.Column="1" Grid.Row="0" Source="stamp.jpg"/>
47 <TextBlock FontSize="18" Margin="10,0" Grid.Column="1" Grid.Row="2">To:</TextBlock>
48 <Line X1="10" Y1="80" X2="190" Y2="80" Stroke="Gray" StrokeThickness="1" Grid.Column="1" Grid.Row="2"/>
49 <Line X1="10" Y1="130" X2="190" Y2="130" Stroke="Gray" StrokeThickness="1" Grid.Column="1" Grid.Row="2"/>
50 <Line X1="10" Y1="180" X2="190" Y2="180" Stroke="Gray" StrokeThickness="1" Grid.Column="1" Grid.Row="2"/>
51 <Line X1="0" Y1="0" X2="0" Y2="300" Stroke="LightGray" StrokeThickness="1" Grid.Column="1" Grid.Row="0" Grid.RowSpan="2"/>
58 <Grid.ColumnDefinitions>
60 <ColumnDefinition MinWidth="200"/>
61 </Grid.ColumnDefinitions>
63 <!-- StackPanel with a couple of elements to control the Postcard -->
64 <StackPanel Grid.Column="1" Margin="20,20" HorizontalAlignment="Center" VerticalAlignment="Center">
65 <WrapPanel HorizontalAlignment="Right">
66 <Label HorizontalAlignment="Left">Rotate X</Label>
67 <Slider Name="sliderX" Minimum="0" Maximum="360" Value="150" MinWidth="180"/>
69 <WrapPanel HorizontalAlignment="Right">
70 <Label HorizontalAlignment="Left">Rotate Y</Label>
71 <Slider Name="sliderY" Minimum="0" Maximum="360" Value="150" MinWidth="180"/>
73 <WrapPanel HorizontalAlignment="Right">
74 <Label HorizontalAlignment="Left">Rotate Z</Label>
75 <Slider Name="sliderZ" Minimum="0" Maximum="360" Value="180" MinWidth="180"/>
77 <WrapPanel HorizontalAlignment="Right">
78 <Label HorizontalAlignment="Left">Zoom</Label>
79 <Slider Name="sliderScale" Minimum="0.1" Maximum="3" Value="1.3" MinWidth="180"/>
81 <Rectangle Height="15"/>
82 <StackPanel Orientation="Horizontal" HorizontalAlignment="Right">
83 <Button Margin="2,2" Name="startButton" IsEnabled="True">Start Animation</Button>
84 <Button Margin="2,2" Name="stopButton" IsEnabled="False">Stop Animation</Button>
86 <Rectangle Height="15"/>
89 <Viewbox Grid.Column="0">
90 <Viewbox.RenderTransform>
91 <ScaleTransform ScaleX = "{Binding ElementName=sliderScale,Path=Value}"
92 ScaleY = "{Binding ElementName=sliderScale,Path=Value}"
95 </Viewbox.RenderTransform>
97 <!-- Viewport3D to host the 3D model of the Postcard -->
98 <Viewport3D Width="600" Height="400">
100 <PerspectiveCamera LookDirection = "0,0,-1"
101 UpDirection = "0,1,0"
106 <ModelVisual3D.Children>
108 <ModelVisual3D.Content>
109 <DirectionalLight Color="#FFFFFF" Direction="0,0,-1"/>
110 </ModelVisual3D.Content>
113 <ModelVisual3D.Content>
114 <DirectionalLight Color="#FFFFFF" Direction="0,0,1"/>
115 </ModelVisual3D.Content>
118 <ModelVisual3D.Content>
120 <GeometryModel3D.Geometry>
121 <MeshGeometry3D TriangleIndices = "0,1,2 3,4,5"
122 Normals = "0,0,1 0,0,1 0,0,1 0,0,1 0,0,1 0,0,1"
123 TextureCoordinates = "0,0 1,0 1,1 1,1 0,1 0,0"
124 Positions = "-0.66,-0.5,0 0.66,-0.5,0 0.66,0.5,0 0.66,0.5,0 -0.66,0.5,0 -0.66,-0.5,0"/>
125 </GeometryModel3D.Geometry>
126 <GeometryModel3D.Material>
128 <DiffuseMaterial.Brush>
129 <VisualBrush Visual="{Binding ElementName=icFront}">
130 <VisualBrush.RelativeTransform>
132 <ScaleTransform ScaleX="1" ScaleY="-1"/>
133 <TranslateTransform Y="1"/>
135 </VisualBrush.RelativeTransform>
137 </DiffuseMaterial.Brush>
139 </GeometryModel3D.Material>
141 </ModelVisual3D.Content>
144 <ModelVisual3D.Content>
146 <GeometryModel3D.Geometry>
147 <MeshGeometry3D TriangleIndices = "0,1,2 3,4,5"
148 Normals = "0,0,-1 0,0,-1 0,0,-1 0,0,-1 0,0,-1 0,0,-1"
149 TextureCoordinates = "1,0 1,1 0,1 0,1 0,0 1,0"
150 Positions = "-0.66,-0.5,0 -0.66,0.5,0 0.66,0.5,0 0.66,0.5,0 0.66,-0.5,0 -0.66,-0.5,0"/>
151 </GeometryModel3D.Geometry>
152 <GeometryModel3D.Material>
154 <DiffuseMaterial.Brush>
155 <VisualBrush Visual="{Binding ElementName=icBack}">
156 <VisualBrush.RelativeTransform>
158 <ScaleTransform ScaleX="1" ScaleY="-1"/>
159 <TranslateTransform Y="1"/>
161 </VisualBrush.RelativeTransform>
163 </DiffuseMaterial.Brush>
165 </GeometryModel3D.Material>
167 </ModelVisual3D.Content>
169 </ModelVisual3D.Children>
170 <ModelVisual3D.Transform>
172 <Transform3DGroup.Children>
174 <RotateTransform3D.Rotation>
175 <AxisAngleRotation3D x:Name = "xRotate"
176 Angle = "{Binding ElementName=sliderX,Path=Value}"
178 </RotateTransform3D.Rotation>
181 <RotateTransform3D.Rotation>
182 <AxisAngleRotation3D x:Name = "yRotate"
183 Angle = "{Binding ElementName=sliderY,Path=Value}"
185 </RotateTransform3D.Rotation>
188 <RotateTransform3D.Rotation>
189 <AxisAngleRotation3D x:Name = "zRotate"
190 Angle = "{Binding ElementName=sliderZ,Path=Value}"
192 </RotateTransform3D.Rotation>
194 </Transform3DGroup.Children>
196 </ModelVisual3D.Transform>
203 <!-- Event triggers to control the animation of the Postcard -->
205 <EventTrigger SourceName="startButton" RoutedEvent="Button.Click">
208 <BooleanAnimationUsingKeyFrames
209 Storyboard.TargetName="startButton"
210 Storyboard.TargetProperty="(Button.IsEnabled)"
212 <DiscreteBooleanKeyFrame Value="False" KeyTime="0:0:0" />
213 </BooleanAnimationUsingKeyFrames>
214 <BooleanAnimationUsingKeyFrames
215 Storyboard.TargetName="stopButton"
216 Storyboard.TargetProperty="(Button.IsEnabled)"
218 <DiscreteBooleanKeyFrame Value="True" KeyTime="0:0:0" />
219 </BooleanAnimationUsingKeyFrames>
222 <BeginStoryboard Name="xRotateStoryboard">
224 <DoubleAnimation Storyboard.TargetName = "xRotate"
225 Storyboard.TargetProperty = "Angle"
229 RepeatBehavior = "Forever"/>
232 <BeginStoryboard Name="yRotateStoryboard">
234 <DoubleAnimation Storyboard.TargetName = "yRotate"
235 Storyboard.TargetProperty = "Angle"
239 RepeatBehavior = "Forever"/>
242 <BeginStoryboard Name="zRotateStoryboard">
244 <DoubleAnimation Storyboard.TargetName = "zRotate"
245 Storyboard.TargetProperty = "Angle"
249 RepeatBehavior = "Forever"/>
253 <EventTrigger SourceName="stopButton" RoutedEvent="Button.Click">
256 <BooleanAnimationUsingKeyFrames
257 Storyboard.TargetName="startButton"
258 Storyboard.TargetProperty="(Button.IsEnabled)"
260 <DiscreteBooleanKeyFrame Value="True" KeyTime="0:0:0" />
261 </BooleanAnimationUsingKeyFrames>
262 <BooleanAnimationUsingKeyFrames
263 Storyboard.TargetName="stopButton"
264 Storyboard.TargetProperty="(Button.IsEnabled)"
266 <DiscreteBooleanKeyFrame Value="False" KeyTime="0:0:0" />
267 </BooleanAnimationUsingKeyFrames>
270 <StopStoryboard BeginStoryboardName="xRotateStoryboard"/>
271 <StopStoryboard BeginStoryboardName="yRotateStoryboard"/>
272 <StopStoryboard BeginStoryboardName="zRotateStoryboard"/>