2014-12-23 1 views
0

다음과 같은 문제가 있습니다. 마우스 오버시 아이콘의 색상 값에 애니메이션을 적용하고 마우스를 놓으면 다시 애니메이션을 적용하려고합니다. 이를 위해 MouseEnter에서 트리거되는 새로운 ColorAnimation을 만들었습니다. 애니메이션의 속성 경로는 "(Path.Fill). (SolidColorBrush.Color)"입니다. 그러나 이것을 실행하면 오류가 발생합니다. '채우기'속성이 'Path (Path.Fill). (SolidColorBrush.Color)'의 DependencyObject를 가리 키지 않습니다. '. 오류의 의미를 이해하는 동안 나는 어떤 속성 경로를 사용해야하는지 잘 모릅니다. 어떤 아이디어? 시간 내 미리 감사드립니다. 불분명 한 것이 있으면 알려주십시오.MouseEnter/MouseLeave (WPF)에서 VisualBrush의 색상 값에 애니메이션 적용

ps. 누구든지 '아이콘/경로'자원을 배치하는 방법에 대한 더 좋은 아이디어가 있다면 나는 많은 의무를진다.

코드;

ColorAnimation mouseEnterColorAnimation = new ColorAnimation { 
    To = Colors.Yellow, 
    Duration = TimeSpan.FromSeconds(1) 
}; 

Storyboard.SetTargetName(mouseEnterColorAnimation, "DeleteIconGrid"); 
Storyboard.SetTargetProperty(mouseEnterColorAnimation, new PropertyPath("Path.Fill).(SolidColorBrush.Color)")); 
Storyboard mouseEnterStoryboard = new Storyboard(); 
mouseEnterStoryboard.Children.Add(mouseEnterColorAnimation); 
mouseEnterStoryboard.Begin(this); 

xaml;

<Grid x:Name="Grid" Background="Transparent" Width="100" Height="100" MouseDown="Grid_MouseDown" MouseEnter="Grid_MouseEnter" MouseLeave="Grid_MouseLeave" > 
    <Grid x:Name="DeleteIconGrid" Width="50" Margin="0,0,0,14"><Grid.Background><VisualBrush Visual="{StaticResource Icon-Delete}" Stretch="Uniform" /></Grid.Background></Grid> 
    <Label Content="Delete icon" HorizontalAlignment="Center" VerticalAlignment="Bottom" Margin="6" Foreground="{DynamicResource Gray}"></Label> 
</Grid> 

자원;

<Canvas x:Key="Icon-Delete" Background="Transparent"> 
    <Path Stretch="Uniform" Fill="LightSlateGray" Data="F1 M 4.70432,0L 0.0480347,4.77802L 7.00842,11.6812L 0,18.7292L 4.70432,23.46L 11.6647,16.412L 18.6252,23.46L 23.3774,18.7774L 16.369,11.6812L 23.3294,4.77802L 18.6252,0L 11.6647,6.9986L 4.70432,0 Z" /> 
</Canvas> 

답변

1

VisualBrush가하는 하지Color 속성을 가지고 ... 당신은 SolidColorBrush와 혼동 될 것으로 보인다. 따라서 VisualBrush의 색상을 애니메이션으로 만들 수는 없지만 SolidColorBrush을 사용할 때는 가능합니다.

당신은 대신이의 ... 당신의 PropertyPath에 실수가 :

"Path.Fill).(SolidColorBrush.Color)" 

가이해야한다 : 마지막으로

"(Path.Fill).(SolidColorBrush.Color)" 

을, 당신이의 Color 속성을 애니메이션을 적용 할 경우 BrushCanvasPath에서와 같이 Fill 속성을 SolidColorBrush의 인스턴스로 설정해야합니다.

01 VisualBrush.Visual 애니메이션을하기 위해 23,516,
<Path Stretch="Uniform" Fill="LightSlateGray" Data="F1 M 4.70432,0L 0.0480347,4.77802L 7.00842,11.6812L 0,18.7292L 4.70432,23.46L 11.6647,16.412L 18.6252,23.46L 23.3774,18.7774L 16.369,11.6812L 23.3294,4.77802L 18.6252,0L 11.6647,6.9986L 4.70432,0 Z" /> 

UPDATE >>>

, 당신은 인라인을 선언해야합니다. Visual Studio 포럼의 VisualBrush Animation 페이지에서이 예제를 가져 오십시오.

<Button Width="320" Height="240"> 
    <Button.Background> 
     <VisualBrush> 
      <VisualBrush.Visual> 
       <Canvas> 
        <Rectangle Width="320" Height="240" Name="myRect" Fill="Blue"> 
         <Rectangle.Triggers> 
          <EventTrigger RoutedEvent="FrameworkElement.Loaded"> 
           <EventTrigger.Actions> 
            <BeginStoryboard> 
             <BeginStoryboard.Storyboard> 
              <Storyboard > 
               <ColorAnimation To="Red" Duration="0:0:2" Storyboard.TargetName="myRect" Storyboard.TargetProperty="Fill.Color" AutoReverse="True" RepeatBehavior="Forever"/> 
              </Storyboard> 
             </BeginStoryboard.Storyboard> 
            </BeginStoryboard> 
           </EventTrigger.Actions> 
          </EventTrigger> 
         </Rectangle.Triggers> 
        </Rectangle> 
       </Canvas> 
      </VisualBrush.Visual> 
     </VisualBrush> 
    </Button.Background> 
</Button> 
+0

Sheridan에게 답장을 보내 주셔서 감사합니다. 올바르게 이해하면 VisualBrush에 Color 속성이 없으므로 SolidColorBrush 자체에 애니메이션을 적용해야합니다. 하지만 이것이 바로 PropertyPath의 권리와 목표가 무엇입니까? ("(Path.Fill). (SolidColorBrush.Color)") 다른 속성을 대상으로해야합니까? – WalterB

+0

'VisualBrush'를 사용할 때 'SolidColorBrush.Color' 속성을 타겟팅 할 수 없습니다. 'VisualBrush' 색상은 당신이 실제로'VisualProperty'의'Visual'을 움직이지 않으면 애니메이션 될 수 없습니다. – Sheridan

+0

그러면 VisualProperty 대신 Visual을 대상으로해야합니까? PropertyPath를 통해 Visual의 color 속성을 어떻게 목표로합니까? – WalterB

관련 문제