0
새 이벤트를 만들지 않으려 고합니다. 선택적으로 페이드 인 또는 아웃 캔버스 컨트롤을 만들 필요가 마우스 위에 있는지 여부에 따라. 아래의 코드는 내가 할 수있는 것보다 더 잘하고 싶은 것을 아마 설명합니다.내 사용자 정의 컨트롤 내에서 이벤트를 처리하려면 어떻게해야합니까?
private Storyboard fadeInStoryboard;
private Storyboard fadeOutStoryboard;
public FadingOptionPanel()
{
InitializeComponent();
}
public static readonly DependencyProperty FadeEnabledProperty =
DependencyProperty.Register("IsFadeEnabled", typeof(bool), typeof(FadingOptionPanel), new FrameworkPropertyMetadata(true,
OnFadeEnabledPropertyChanged,
OnCoerceFadeEnabledProperty));
public bool IsFadeEnabled
{
get
{
return (bool)GetValue(FadeEnabledProperty);
}
set
{
SetValue(FadeEnabledProperty, value);
}
}
private static void OnFadeEnabledPropertyChanged(DependencyObject source,
DependencyPropertyChangedEventArgs e)
{
}
private static object OnCoerceFadeEnabledProperty(DependencyObject sender, object data)
{
if (data.GetType() != typeof(bool))
{
data = true;
}
return data;
}
private void FadingOptionPanel_MouseEnter(object sender, MouseEventArgs e)
{
if (IsFadeEnabled)
{
fadeInStoryboard.Begin(this);
}
}
private void FadingOptionPanel_MouseLeave(object sender, MouseEventArgs e)
{
if (IsFadeEnabled)
{
fadeOutStoryboard.Begin(this);
}
}
private void FadingOptionsPanel_Loaded(object sender, RoutedEventArgs e)
{
//Initialize Fade In Animation
DoubleAnimation fadeInDoubleAnimation = new DoubleAnimation();
fadeInDoubleAnimation.From = 0;
fadeInDoubleAnimation.To = 1;
fadeInDoubleAnimation.Duration = new Duration(TimeSpan.FromSeconds(.5));
fadeInStoryboard = new Storyboard();
fadeInStoryboard.Children.Add(fadeInDoubleAnimation);
Storyboard.SetTargetName(fadeInDoubleAnimation, this.Name);
Storyboard.SetTargetProperty(fadeInDoubleAnimation, new PropertyPath(Canvas.OpacityProperty));
//Initialize Fade Out Animation
DoubleAnimation fadeOutDoubleAnimation = new DoubleAnimation();
fadeOutDoubleAnimation.From = 1;
fadeOutDoubleAnimation.To = 0;
fadeOutDoubleAnimation.Duration = new Duration(TimeSpan.FromSeconds(.2));
fadeOutStoryboard = new Storyboard();
fadeOutStoryboard.Children.Add(fadeOutDoubleAnimation);
Storyboard.SetTargetName(fadeOutDoubleAnimation, this.Name);
Storyboard.SetTargetProperty(fadeOutDoubleAnimation, new PropertyPath(Canvas.OpacityProperty));
}
원래 usercontrols가 콘텐츠를 지원하지 않는다는 것을 알기 전에 나는이 코드를 사용자 정의 컨트롤 대신 usercontrol 내부에서 사용하고있었습니다.
감사합니다. 그러나 " ''Minimalistic_Writer.FadingCanvas '의 이름 범위에서 이름을 찾을 수 없습니다." "fadeInStoryboard.Begin (this);"에서 – Justin
내 생각 엔 Loaded 핸들러에서 this.Name이 null을 리턴한다는 것입니다. TargetName 대신 Target 속성을 설정해보십시오. 'Storyboard.Target = this;'. – itowlson
대단히 고마워요! – Justin