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();
    }

inputTextArea losing focus in IE8

I have a jsf 2.0 application in which I have an input text box and a number characters left counter at the bottom of input text box which I am updating through javascript.

<h:inputTextarea class="myInputTextClass"
value="#{bean.text}"
style="resize: none;width:445px;" type="text"
maxlength="255" cols="60" rows="3"
onfocus="countChars($('.myInputTextClass'),255)"
onkeyup="countChars($('.myInputTextClass'),255);"
onkeydown="countChars($('.myInputTextClass'),255);"
/>

<span id="char_count" style="font-style:italic;margin-left:-14px">255</span>

Script:

function countChars(element,  max) {

  calculateCount(element.val().length, max);
  if (element.val().length > max) { 
    element.val(element.val().substring(0, max));
   }

  }

function calculateCount(length, max){
 var count = max - length;
    if(count &lt; 0){
    count = 0;
    }
   document.getElementById('char_count').innerHTML =  count ;
}

The problem is after typing in somewhere around 150 characters in the input text box, the focus shifts back to top of inputtextbox. However, the cursor remains at the end as expected.

I tried using the scrollTop position and focus but didn't work. Any suggestion is highly appreciated.

This issue happens only in IE8, in forefox it works fine.

4

1 回答 1

2

Completed事件的类型是EventHandler<object>,但您声明事件处理程序是类型EventHandler,而不是EventHandler<object>

这正是错误消息告诉您的内容,因此您应该将事件处理程序的类型更改为 EventHandler<object>.

顺便说一句,事件处理程序sb.Completed+= ehl; 的行似乎很奇怪。每次调用事件处理程序时,您基本上都会再次将处理程序附加到事件。

于 2013-03-28T07:48:20.123 回答