<!-- Front of shape shows the content of "frontHost" --> <GeometryModel3D.Material> <DiffuseMaterial> <DiffuseMaterial.Brush> <VisualBrush Visual="{Binding ElementName=frontHost}" /> </DiffuseMaterial.Brush> </DiffuseMaterial> </GeometryModel3D.Material>
<!-- Back of shape shows the content of "backHost" --> <GeometryModel3D.BackMaterial> <DiffuseMaterial> <DiffuseMaterial.Brush> <VisualBrush Visual="{Binding ElementName=backHost}"> <VisualBrush.RelativeTransform> <!-- By default, this would come out backwards because we"re on the back on the shape. Flip it to make it right. --> <ScaleTransform ScaleX="-1" CenterX="0.5" /> </VisualBrush.RelativeTransform> </VisualBrush> </DiffuseMaterial.Brush> </DiffuseMaterial> </GeometryModel3D.BackMaterial>
<!-- We use a pair of nested Borders to wrap the content that"s going to go on each side of the rotating model. The reason is that we need to be able to fade these real bits of UI in and out as we transition from front to back, but we need to make sure the VisualBrush in the 3D model doesn"t also get faded out. So the VisualBrush uses the inner Border, while the fade is applied to the outer one. --> <Border x:Name="frontWrapper"> <!-- Note, it"s important that this element has visuals that completely fill the space, as otherwise it messes with the VisualBrush"s size in the 3D model. Setting the background has that effect, even a transparent one. --> <Border x:Name="frontHost" Background="Transparent"> <Border.Triggers> <EventTrigger RoutedEvent="Grid.MouseDown"> <BeginStoryboard> <Storyboard> <!-- Make the Viewport3D visible only for the duration of the rotation. --> <ObjectAnimationUsingKeyFrames Storyboard.TargetName="vp3D" Storyboard.TargetProperty="Visibility"> <DiscreteObjectKeyFrame KeyTime="0:0:0" Value="{x:Static Visibility.Visible}" /> <DiscreteObjectKeyFrame KeyTime="0:0:1.1" Value="{x:Static Visibility.Hidden}" /> </ObjectAnimationUsingKeyFrames>
<!-- Make the background element visible. (It won"t actually appear until it is faded in right at the end of the animation.) --> <ObjectAnimationUsingKeyFrames Storyboard.TargetName="backWrapper" Storyboard.TargetProperty="Visibility"> <DiscreteObjectKeyFrame KeyTime="0:0:1" Value="{x:Static Visibility.Visible}"/> </ObjectAnimationUsingKeyFrames>
<!-- Hide the foreground element. It will already be invisible by this time because we fade it out right at the start of the animation. However, until we set its Visibility to Hidden, it will still be visible to the mouse --> <ObjectAnimationUsingKeyFrames Storyboard.TargetName="frontWrapper" Storyboard.TargetProperty="Visibility"> <DiscreteObjectKeyFrame KeyTime="0:0:0.05" Value="{x:Static Visibility.Hidden}" /> </ObjectAnimationUsingKeyFrames>
<!-- Fade the front wrapper out. The Viewport3D is behind us, so it"ll fade into view at this point. The reason for fading is to avoid a visible step as we switch from the real UI to the copy projected onto the 3D model. --> <DoubleAnimation To="0" Duration="0:0:0.05" Storyboard.TargetName="frontWrapper" Storyboard.TargetProperty="Opacity" />
<!-- Fade the back wrapper in. Once the spin completes, we fade the real back UI in over the Viewport3D - using a fade to avoid a sudden jolt between the slightly fuzzy 3D look and the real UI. --> <DoubleAnimation BeginTime="0:0:1.05" Duration="0:0:0.05" To="1" Storyboard.TargetName="backWrapper" Storyboard.TargetProperty="Opacity" />
<!-- 3D animation. Move the camera out slightly as we spin, so the model fits entirely within the field of view. Rotate the model 180 degrees. --> <Point3DAnimation To="0,0,1.1" From="0,0,0.5" BeginTime="0:0:0.05" Duration="0:0:0.5" AutoReverse="True" DecelerationRatio="0.3" Storyboard.TargetName="camera" Storyboard.TargetProperty="(PerspectiveCamera.Position)" /> <DoubleAnimation From="0" To="180" AccelerationRatio="0.3" DecelerationRatio="0.3" BeginTime="0:0:0.05" Duration="0:0:1" Storyboard.TargetName="rotate" Storyboard.TargetProperty="Angle" /> </Storyboard> </BeginStoryboard> </EventTrigger> </Border.Triggers> <ContentPresenter Content="{Binding}" ContentTemplate="{StaticResource frontTemplate}" /> </Border> </Border> <Border x:Name="backWrapper" Grid.Column="0" Visibility="Hidden" Opacity="0"> <Border x:Name="backHost" Background="Transparent"> <Border.Triggers> <EventTrigger RoutedEvent="Grid.MouseDown"> <BeginStoryboard> <Storyboard> <ObjectAnimationUsingKeyFrames Storyboard.TargetName="vp3D" Storyboard.TargetProperty="Visibility"> <DiscreteObjectKeyFrame KeyTime="0:0:0" Value="{x:Static Visibility.Visible}" /> <DiscreteObjectKeyFrame KeyTime="0:0:1.1" Value="{x:Static Visibility.Hidden}" /> </ObjectAnimationUsingKeyFrames>