2

I am trying to fade a text box within specified time. This code works on Windows Phone but it doesn't work in a Windows 8 application. I made changes to fix as many errors as possible. but I couldn't resolve one of them: cannot implicitly convert type 'System.EventHandler' to 'System.EventHandler<object>" arises on the expression sb.Completed += ehl. The full function is below:

    public static void Fade(UIElement target, double ValueFrom, double ValueTo, double Duration)
    {
        DoubleAnimation da = new DoubleAnimation();
        da.From = ValueFrom;
        da.To = ValueTo;
        da.Duration = TimeSpan.FromSeconds(Duration);
        da.AutoReverse = false;

        Windows.UI.Xaml.Media.Animation.Storyboard.SetTargetProperty(da, "opacity");

        Windows.UI.Xaml.Media.Animation.Storyboard.SetTarget(da, target);

        Windows.UI.Xaml.Media.Animation.Storyboard sb = new Windows.UI.Xaml.Media.Animation.Storyboard();
        sb.Children.Add(da);

        EventHandler ehl = null;
        ehl = (s, args) =>
        {

            sb.Stop();
            sb.Completed+= ehl; //error occurs here
            target.Opacity = ValueTo;
        };
        sb.Completed += ehl; //error occurs here

        sb.Begin();
    }

From the documentation:

The content mode specifies how the cached bitmap of the view’s layer is adjusted when the view’s bounds change.

For an image view, this is talking about the image. For a view that draws its content, this is talking about the drawn content. It does not affect the layout of subviews.

You need to look at the autoresizing masks in place on the subviews. Content mode is a red herring here. If you can't achieve the layout you need using autoresizing masks, then you need to implement layoutSubviews and calculate the subview positions and frames manually.

from jrturton's answer to: https://stackoverflow.com/a/14111480/1374512

4

1 に答える 1

2

CompletedイベントのタイプはEventHandler<object>ですが、イベント ハンドラのタイプはではEventHandlerなく であると宣言していますEventHandler<object>

これはまさにエラー メッセージが示す内容であるため、イベント ハンドラのタイプを に変更する必要があります EventHandler<object>

ところで、イベント ハンドラsb.Completed+= ehl; の行は奇妙に思えます。基本的に、イベントハンドラーが呼び出されるたびに、ハンドラーをイベントに再度アタッチしています。

于 2013-03-28T07:48:20.123 に答える