테이블 셀과 같은 격자 모양으로 배열 된 사각형의 애니메이션을 사용하는 코드로 작업하고 있습니다. 애니메이션은 지금 mouseover 이벤트에서 트리거되지만 대신 자신의 사용자 정의 메소드 호출로 대체해야합니다. 터치리스 커서 (kinect 사용)로 작업하고 기본적으로 커서가 현재 마우스/마우스 오버 속성과 비슷한 특정 셀/사각형에 있는지를 확인하는 자체 메서드가 기본적으로 있기 때문에 필요합니다. 다음은 현재 사용중인 애니메이션 스타일 코드입니다.WPF에서 사용자 정의 메서드 호출로 마우스 이벤트 호출을 바꾸는 방법 애니메이션 스타일
Style PrepareAnimationStyle(String label)
{
Trigger animTrigger = new Trigger();
animTrigger.Property = ContentElement.IsMouseOverProperty; //currently set on mouse hover. Will have to call explicitly for cursor.
animTrigger.Value = true;
System.Windows.Media.Animation.ColorAnimation greenStroke = new System.Windows.Media.Animation.ColorAnimation((Color)ColorConverter.ConvertFromString("#FF66CC00"), TimeSpan.FromSeconds(0));
//greenStroke.FillBehavior = FillBehavior.HoldEnd;
System.Windows.Media.Animation.ColorAnimation greenFill = new System.Windows.Media.Animation.ColorAnimation((Color)ColorConverter.ConvertFromString("#FF66CC00"), TimeSpan.FromSeconds(0));
//greenFill.FillBehavior = FillBehavior.HoldEnd;
System.Windows.Media.Animation.ColorAnimation transparentFill = new System.Windows.Media.Animation.ColorAnimation(Colors.Transparent, TimeSpan.FromSeconds(1));
System.Windows.Media.Animation.ColorAnimation silverStroke = new System.Windows.Media.Animation.ColorAnimation(Colors.Silver, TimeSpan.FromSeconds(1));
System.Windows.Media.Animation.Storyboard sbEnter = new System.Windows.Media.Animation.Storyboard();
Storyboard.SetTargetProperty(greenStroke, new PropertyPath("Stroke.Color"));
Storyboard.SetTargetProperty(greenFill, new PropertyPath("Fill.Color"));
sbEnter.Children.Add(greenStroke);
sbEnter.Children.Add(greenFill);
Storyboard sbExit = new Storyboard();
Storyboard.SetTargetProperty(silverStroke, new PropertyPath("Stroke.Color"));
Storyboard.SetTargetProperty(transparentFill, new PropertyPath("Fill.Color"));
sbExit.Children.Add(silverStroke);
sbExit.Children.Add(transparentFill);
animTrigger.EnterActions.Add(new BeginStoryboard() { Storyboard = sbEnter });
if (label != "chills")
animTrigger.ExitActions.Add(new BeginStoryboard() { Storyboard = sbExit });
Style cellStyle = new Style();
cellStyle.Triggers.Add(animTrigger);
return cellStyle;
}
이 줄을 바꿀 수 있습니까? :
animTrigger.Property = ContentElement.IsMouseOverProperty;
이 작업을 수행 할 수 있습니까? 그렇다면 어떻게 자체 메서드 호출로 바꿀 수 있습니까?
대신 특정 UI 요소에 액세스하여 명시 적으로 mouseover 속성을 True로 설정할 수 있습니까? 다음과 같은 것 :
foreach (UIElement ui in grid.Children)
{
int index = grid.Children.IndexOf(ui);
int rowIndex = index/numOfCols;
int columnIndex = index % numOfCols;
if (rowIndex == 0 && columnIndex == 5)
if (ui is System.Windows.Shapes.Rectangle)
ui.SetValue(UIElement.IsMouseOverProperty, true);
}
두 번째 방법이 효과가 있습니까? 속성을 false로 설정해야합니까?
도와주세요!