Report a Silverlight Bughttp://forums.silverlight.net//28.aspx/1?Report+a+Silverlight+BugFound a bug in Silverlight? Use this forum to describe the bug and the code or steps to reproduce it.Mon, 01 Jan 0001 00:00:00 -050028167018http://forums.silverlight.net//p/69067/167018.aspx/1?Succesive+IsEnable+true+false+on+textbox+breaks+its+behaviors+Succesive IsEnable true/false on textbox breaks its behaviors. <p>Good day everyone.</p> <p>Ok this is the problem and the way to reproduce it. I have two textboxs and one button. The clic event Disable the UserControl and launch a timer of 1 sec.The timer event tick restore the state of UserControl (IsEnable = true)</p> <p>After a various number of clic event, textbox are graphicaly enable, but there is no way to enter text anymore. the blincking bar is vivible on textbox (even if it hasen't focus).<br> </p> <p>&nbsp;Sorry for my english. I am far better in french ;)<br> </p> <p>&nbsp;<br> </p> <p>&nbsp;EDIT: I fogot to mention you have to insert some text in textbox between each clic to repoduce the problem (one of the textbox must have the focus when you clic on the button</p> <p>&nbsp;</p> <p><b>C# code </b><br> </p> <p>&nbsp;namespace TestBoxEnable<br> {<br> &nbsp;&nbsp;&nbsp; public partial class Page : UserControl<br> &nbsp;&nbsp;&nbsp; {<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; DispatcherTimer _timer = new DispatcherTimer();<br> <br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; public Page()<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; {<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; InitializeComponent();<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }<br> <br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; private void Button_Click(object sender, RoutedEventArgs e)<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; {<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; this.IsEnabled = false;<br> <br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; _timer = new DispatcherTimer();<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; _timer.Interval = new TimeSpan(0, 0, 1);<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; _timer.Tick &#43;= new EventHandler(_timer_Tick);<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; _timer.Start();<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }<br> <br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; void _timer_Tick(object sender, EventArgs e)<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; {<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; this.IsEnabled = true;<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }<br> &nbsp;&nbsp;&nbsp; }<br> }<br> <br> </p> <p><b>&nbsp;Xmal </b><br> </p> <p>&nbsp;&lt;UserControl x:Class=&quot;TestBoxEnable.Page&quot;<br> &nbsp;&nbsp;&nbsp; xmlns=&quot;http://schemas.microsoft.com/winfx/2006/xaml/presentation&quot; <br> &nbsp;&nbsp;&nbsp; xmlns:x=&quot;http://schemas.microsoft.com/winfx/2006/xaml&quot; <br> &nbsp;&nbsp;&nbsp; Width=&quot;400&quot; Height=&quot;300&quot;&gt;<br> &nbsp;&nbsp;&nbsp; &lt;Canvas x:Name=&quot;LayoutRoot&quot; Background=&quot;White&quot;&gt;<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &lt;TextBox Text=&quot;Test&quot; x:Name=&quot;txt1&quot; Canvas.Left=&quot;0&quot; Canvas.Top=&quot;0&quot;/&gt;<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &lt;TextBox Text=&quot;Test2&quot; x:Name=&quot;txt2&quot; Canvas.Left=&quot;0&quot; Canvas.Top=&quot;25&quot;/&gt;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &lt;Button Content=&quot;Disable&quot; Click=&quot;Button_Click&quot; x:Name=&quot;btn&quot; Canvas.Left=&quot;0&quot; Canvas.Top=&quot;50&quot;/&gt;<br> &nbsp;&nbsp;&nbsp; &lt;/Canvas&gt;<br> &lt;/UserControl&gt;</p> 2009-01-28T10:35:30-05:00167032http://forums.silverlight.net//p/69067/167032.aspx/1?Re+Succesive+IsEnable+true+false+on+textbox+breaks+its+behaviors+Re: Succesive IsEnable true/false on textbox breaks its behaviors. <p>hi,</p> <p>private void Button_Click(object sender, RoutedEventArgs e)<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; {<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; this.IsEnabled = false;</p> <p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; //&nbsp; _timer = new DispatcherTimer();<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; _timer.Interval = new TimeSpan(0, 0, 1);<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; _timer.Tick &#43;= new EventHandler(_timer_Tick);<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; _timer.Start();<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }</p> <p><br> &nbsp;void _timer_Tick(object sender, EventArgs e)<br> &nbsp;{<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; this.IsEnabled = true;</p> <p>&nbsp;&nbsp;&nbsp; //stop the timer here.<br> &nbsp;&nbsp;&nbsp; _timer.Stop() // or try ((DispatcherTimer)sender).Stop();<br> &nbsp;}<br> </p> <p>****</p> <p>Please remember to mark the replies as answers if they help and unmark them if they provide no help.<br> </p> <p>Regards</p> <p>Raag</p> 2009-01-28T11:17:50-05:00167051http://forums.silverlight.net//p/69067/167051.aspx/1?Re+Succesive+IsEnable+true+false+on+textbox+breaks+its+behaviors+Re: Succesive IsEnable true/false on textbox breaks its behaviors. <p>&nbsp;Even with a cleaner code like that. the problem still persist...</p> <p>I fogot to mention you have to insert some text in textbox between each clic to repoduce the problem (one of the textbox must have the focus when you clic on the button<br> </p> <p>&nbsp;</p> <p>public partial class Page : UserControl<br> &nbsp;&nbsp;&nbsp; {<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; DispatcherTimer _timer = new DispatcherTimer();<br> <br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; public Page()<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; {<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; InitializeComponent();<br> <br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; _timer.Interval = new TimeSpan(0, 0, 1);<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; _timer.Tick &#43;= new EventHandler(_timer_Tick);<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }<br> <br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; private void Button_Click(object sender, RoutedEventArgs e)<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; {<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; this.IsEnabled = false;<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; _timer.Start();<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }<br> <br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; void _timer_Tick(object sender, EventArgs e)<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; {<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; this.IsEnabled = true;<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; ((DispatcherTimer)sender).Stop();<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }<br> &nbsp;&nbsp;&nbsp; } <br> </p> 2009-01-28T11:58:31-05:00167441http://forums.silverlight.net//p/69067/167441.aspx/1?Re+Re+Succesive+IsEnable+true+false+on+textbox+breaks+its+behaviors+Re: Re: Succesive IsEnable true/false on textbox breaks its behaviors. <p>hi,,,</p> <p>Tell me what you want to acheive in txt1 and txt2 on each click...</p> 2009-01-29T07:49:24-05:00167466http://forums.silverlight.net//p/69067/167466.aspx/1?Re+Re+Succesive+IsEnable+true+false+on+textbox+breaks+its+behaviors+Re: Re: Succesive IsEnable true/false on textbox breaks its behaviors. <p>&nbsp;hi, thanks for you concern.<br> </p> <p>&nbsp;The purpose is the the traditionnal login credential dialog...</p> <p>So basicaly, I get value from the textbox and send it to a webservice. I Disable the &quot;Dialog&quot; until WS response. (so in the real case it is not a timer event but a completed event and of course it is not two textbox but also a passordbox). There is possibility of an incorrect combination of log/pass. But it will do the same with some kind of&nbsp; &quot;form&quot; submition. And the strange behavior of textbox fire already on the fourth try. <br> </p> <p>Can you reproduce it with the code provided? </p> <p>Fred. <br> </p> 2009-01-29T08:57:51-05:00167679http://forums.silverlight.net//p/69067/167679.aspx/1?Re+Re+Succesive+IsEnable+true+false+on+textbox+breaks+its+behaviors+Re: Re: Succesive IsEnable true/false on textbox breaks its behaviors. <p>Fred,</p> <p>the timer event is perhaps not in the UI thread. Have you tried to use Dispatcher.BeginInvoke to be sure that the code that modified the UI is on the UI thread?</p> <p>I also had problems with disabling a DatePicker during a server call and re-enabling it after.</p> <p>The solution I finally use it to put a Canvas on top of the UI. I set its Width/Height to 0 for normal work and to the size of the plug-in to hide the UI from the mouse. To hide the keyboard, you had to add a UserControl to the Canvas, with the TabNavigation property set to Cycle. When you want to hide the UI, set the focus to the user control. When you receive the response from the server, set the focus to the previous control. Then main page for my application looks like the following:</p> <p>&nbsp;</p> <pre class="prettyprint">&lt;<span class="tag">UserControl</span><span class="attr"> xmlns=</span><span class="attrv">"http://schemas.microsoft.com/client/2007"</span> <span class="attr"> xmlns:x=</span><span class="attrv">"http://schemas.microsoft.com/winfx/2006/xaml"</span> <span class="attr"> x:Class=</span><span class="attrv">"OrdinaSoft.Windows.CMainPage"</span> <span class="attr"> TabNavigation=</span><span class="attrv">"Cycle"</span>&gt; &lt;<span class="tag">Grid</span><span class="attr"> Name=</span><span class="attrv">"MainGrid"</span>&gt; &lt;<span class="tag">Grid.RowDefinitions</span>&gt; &lt;<span class="tag">RowDefinition</span><span class="attr"> Height=</span><span class="attrv">"Auto"</span> /&gt; &lt;/<span class="tag">Grid.RowDefinitions</span>&gt; &lt;<span class="tag">Grid.ColumnDefinitions</span>&gt; &lt;<span class="tag">ColumnDefinition</span><span class="attr"> Width=</span><span class="attrv">"Auto"</span> /&gt; &lt;/<span class="tag">Grid.ColumnDefinitions</span>&gt; &lt;<span class="tag">Canvas</span><span class="attr"> Name=</span><span class="attrv">"HideUICanvas"</span> <span class="attr"> Background=</span><span class="attrv">"Transparent"</span> <span class="attr"> Height=</span><span class="attrv">"0"</span> <span class="attr"> Width=</span><span class="attrv">"0"</span>&gt; &lt;<span class="tag">UserControl</span><span class="attr"> Name=</span><span class="attrv">"HideUIFocusCtrl"</span> <span class="attr"> TabNavigation=</span><span class="attrv">"Cycle"</span> /&gt; &lt;/<span class="tag">Canvas</span>&gt; &lt;/<span class="tag">Grid</span>&gt; &lt;/<span class="tag">UserControl</span>&gt;</pre>&nbsp;Patrick <br> 2009-01-29T19:43:16-05:00167729http://forums.silverlight.net//p/69067/167729.aspx/1?Re+Re+Succesive+IsEnable+true+false+on+textbox+breaks+its+behaviors+Re: Re: Succesive IsEnable true/false on textbox breaks its behaviors. <p>&nbsp;Thank you Patrick,</p> <p>I will try this way, but it is only a workaround. </p> <p>I didn't suspected UI thread problem because at the good time of winform, accessing UI by another Thread lauch an exception. I don't understant why it s not the case in silverlight. But that not my concern right now.<br> </p> <p>The thing that made me think it is bug. It is that after the problem occur, TextBox are graphicaly enable but not in its behavior (you cannot enter text anymore) The textbox seems to have the focus because there is the blinking cursor on the control(so you can have blinking cursor on Both Textbox witch is ridiculous for the user experience)</p> <p>It's realy simple to reproduce (at least on my desk)</p> <p>- Clic on the first textbox <br> </p> <p>- Insert some random text.</p> <p>- Clic on the button </p> <p>-(after one second all the control are enable.. focus still on the textbox no need to click again to this control to insert random text)<br> </p> <p>-repeat the process 1 more time. (the focus seems leave correctly the textbox the first time when you clic the button but not the second. Cursor still blink even in IsEnable=false!) </p> <p>And after&nbsp; some test, there is realy a probleme with focus...</p> <p>During the button clic event, I use UIElement element = (UIElement) FocusManager.GetFocusedElement(); </p> <p>The first time element type is button. but not the second time!!! element type is textbox.</p> <p>&nbsp;</p> <p>Fred. <br> </p> <p><br> </p> <p>&nbsp; <br> </p> 2009-01-29T21:09:55-05:00167903http://forums.silverlight.net//p/69067/167903.aspx/1?Re+Re+Succesive+IsEnable+true+false+on+textbox+breaks+its+behaviors+Re: Re: Succesive IsEnable true/false on textbox breaks its behaviors. <p></p> <blockquote><span class="icon-blockquote"></span> <h4>Azetoth</h4> <p></p> <p>I didn't suspected UI thread problem because at the good time of winform, accessing UI by another Thread lauch an exception. I don't understant why it s not the case in silverlight. But that not my concern right now.</p> <p></p> </blockquote> &nbsp; <p></p> <p>Fred,</p> <p>In the case of my DatePicker, I also receive no exception for setting IsEnabled from another thread (the setting was on the UserControl at the top of the UI). The bug was there!</p> <p>The DatePicker simply no more answer to keyboard events after that.</p> <p>Patrick <br> </p> 2009-01-30T04:47:40-05:00168433http://forums.silverlight.net//p/69067/168433.aspx/1?Re+Re+Succesive+IsEnable+true+false+on+textbox+breaks+its+behaviors+Re: Re: Succesive IsEnable true/false on textbox breaks its behaviors. <p>Patrick, <br> </p> <p>The UI access is on the UI Thread (with the use of Dispatcher.BenginInvoke) doesn't resolve the issue. <br> </p> <p>But thank you very much, I ll try to use your workaround. And hope Silverlight team resolved this bug (that of course doesn't show up on WPF) for v3 release.<br> </p> <p>Fred.<br> </p> <p>&nbsp;</p> <p>My new code with accesUI on the same Thread with the sme problem.<br> </p> <p>&nbsp;public Page()<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; {<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; InitializeComponent();<br> <br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; _timer.Interval = new TimeSpan(0, 0, 1);<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; _timer.Tick &#43;= new EventHandler(_timer_Tick);<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }<br> <br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; private void Button_Click(object sender, RoutedEventArgs e)<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; {<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; UIElement element = (UIElement)FocusManager.GetFocusedElement();<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; txt1.IsEnabled = false;<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; txt2.IsEnabled = false;<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; btn.IsEnabled = false;<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; _timer.Start();<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }<br> <br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; void _timer_Tick(object sender, EventArgs e)<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; {<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Dispatcher.BeginInvoke(delegate()<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; {<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; txt1.IsEnabled = true;<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; txt2.IsEnabled = true;<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; btn.IsEnabled = true;<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; ((DispatcherTimer)sender).Stop();<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; });<br> <br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; } <br> </p> 2009-01-31T14:15:51-05:00