Click here to Skip to main content
15,892,298 members
Please Sign up or sign in to vote.
5.00/5 (1 vote)
See more:
Hi Guys

I want to add a selection effect to my 3d models so that when I select a model it fades to another color, and when deselecting it, it should fade back to it's original color again. The idea I have is to create a Storyboard, and somewhere in the code behind start the Storyboard when a certain model is selected, but, how would I go about specifying the actual fade effect e.g brown to red?
Posted

1 solution

You could do this using a ColorAnimationUsingKeyFrames as in the following sample:
XML
<Window
  xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
  xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
  x:Class="FadeSample.Window1"
  x:Name="Window"
  Title="Window1"
  Width="640" Height="480">
  <Window
  xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
  xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
  x:Class="FadeSample.Window1"
  x:Name="Window"
  Title="Window1"
  Width="640" Height="480">
  <Window.Resources>
    <Storyboard x:Key="OnClick1">
      <ColorAnimationUsingKeyFrames 
        BeginTime="00:00:00" Storyboard.TargetName="button" 
        Storyboard.TargetProperty="(Panel.Background).(SolidColorBrush.Color)">
        <SplineColorKeyFrame KeyTime="00:00:01" Value="#FFEF1407"/>
      </ColorAnimationUsingKeyFrames>
    </Storyboard>
  </Window.Resources>
  <Window.Triggers>
    <EventTrigger 
      RoutedEvent="ButtonBase.Click" SourceName="button">
      <BeginStoryboard Storyboard="{StaticResource OnClick1}"/>
    </EventTrigger>
  </Window.Triggers>

  <Grid x:Name="LayoutRoot">
    <Button 
      HorizontalAlignment="Left" 
      VerticalAlignment="Top" 
      Content="Button" 
      RenderTransformOrigin="3.339,5.055" 
      Margin="120,115,0,0" 
      Background="#FFDF891A" 
      x:Name="button"/>
  </Grid>
</Window>

 
Share this answer
 
v2


CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900