<?xml version="1.0" encoding="UTF-8" ?>
<?xml-stylesheet type="text/xsl" href="http://forums.silverlight.net/utility/FeedStylesheets/rss.xsl" media="screen"?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/" xmlns:wfw="http://wellformedweb.org/CommentAPI/"><channel><title>Report a Silverlight Bug</title><link>http://forums.silverlight.net/forums/28.aspx</link><description>Found a bug in Silverlight? Use this forum to describe the bug and the code or steps to reproduce it.</description><dc:language>en</dc:language><generator>CommunityServer 2007 (Build: 20416.853)</generator><item><title>TextBox skipping every other "set" when appending.</title><link>http://forums.silverlight.net/forums/thread/149027.aspx</link><pubDate>Wed, 17 Dec 2008 05:22:50 GMT</pubDate><guid isPermaLink="false">d0d632c8-a6f7-4f68-b0ce-26aaafd62132:149027</guid><dc:creator>MichaelLPerry1971</dc:creator><slash:comments>0</slash:comments><comments>http://forums.silverlight.net/forums/thread/149027.aspx</comments><wfw:commentRss>http://forums.silverlight.net/forums/commentrss.aspx?SectionID=28&amp;PostID=149027</wfw:commentRss><description>&lt;p&gt;I have a Silverlight 2.0 user control containing a two-way bound TextBox. It is bound to a CLR property on an object that implements INotifyPropertyChanged. The text box is not calling my property setter every time the text box is edited. It appears to skip every other edit.&lt;/p&gt;&lt;p&gt;The way in which I fire PropertyChanged is unusual and appears to be related to the bug. I use the DispatcherSynchronizationContext to delay the event. I am using this technique to queue update notifications until after all changes have taken place. This technique works well in WPF. When I comment out this code and instead fire the event directly, Silverlight also works. I would like to be able to use this technique within Silverlight.&lt;/p&gt;&lt;p&gt;To reproduce the problem, enter the text &amp;quot;a&amp;quot; in the first text box and tab out. Then go back to the first text box and append a &amp;quot;b&amp;quot; and tab out. The first text box will show &amp;quot;ab&amp;quot; but the others will show &amp;quot;a&amp;quot;. Then go back again and append a &amp;quot;c&amp;quot;. Now all three show &amp;quot;abc&amp;quot;. If you select and replace parts of the text, the problem does not occur.&lt;br /&gt;&lt;/p&gt;&lt;p&gt;Thank you for your help. &lt;br /&gt;&lt;/p&gt;&lt;p&gt;Here is the source code:&lt;/p&gt;&lt;p&gt;Document.cs&lt;/p&gt;&lt;p&gt;&amp;nbsp;&lt;/p&gt;&lt;pre class="coloredcode"&gt;&lt;span class="kwd"&gt;using&lt;/span&gt; System.ComponentModel;
&lt;span class="kwd"&gt;using&lt;/span&gt; System.Threading;
&lt;span class="kwd"&gt;using&lt;/span&gt; System.Windows.Threading;

&lt;span class="kwd"&gt;namespace&lt;/span&gt; SLBindingSetterBug
{
    &lt;span class="kwd"&gt;public class&lt;/span&gt; Document : INotifyPropertyChanged
    {
        &lt;span class="kwd"&gt;private static&lt;/span&gt; SendOrPostCallback _callback = &lt;span class="kwd"&gt;new&lt;/span&gt; SendOrPostCallback(TriggerUpdate);

        &lt;span class="kwd"&gt;private static void&lt;/span&gt; TriggerUpdate(&lt;span class="kwd"&gt;object&lt;/span&gt; obj)
        {
            Document p = (Document)obj;
            p.FirePropertyChanged(&lt;span class="st"&gt;&amp;quot;MyText&amp;quot;&lt;/span&gt;);
        }

        &lt;span class="kwd"&gt;public event&lt;/span&gt; PropertyChangedEventHandler PropertyChanged;

        &lt;span class="kwd"&gt;private string&lt;/span&gt; _myText;

        &lt;span class="kwd"&gt;public string&lt;/span&gt; MyText
        {
            &lt;span class="kwd"&gt;get&lt;/span&gt;
            {
                &lt;span class="kwd"&gt;return&lt;/span&gt; _myText;
            }
            &lt;span class="kwd"&gt;set&lt;/span&gt;
            {
                _myText = &lt;span class="kwd"&gt;value&lt;/span&gt;;
                DispatcherSynchronizationContext.Current.Post(_callback, &lt;span class="kwd"&gt;this&lt;/span&gt;);
            }
        }

        &lt;span class="kwd"&gt;private void&lt;/span&gt; FirePropertyChanged(&lt;span class="kwd"&gt;string&lt;/span&gt; propertyName)
        {
            &lt;span class="kwd"&gt;if&lt;/span&gt; (PropertyChanged != &lt;span class="kwd"&gt;null&lt;/span&gt;)
                PropertyChanged.Invoke(&lt;span class="kwd"&gt;this&lt;/span&gt;, &lt;span class="kwd"&gt;new&lt;/span&gt; PropertyChangedEventArgs(propertyName));
        }
    }
}
&lt;/pre&gt;&amp;nbsp;&amp;nbsp;&lt;p&gt;Page.xaml&lt;/p&gt;&lt;p&gt;&amp;nbsp;&lt;/p&gt;&lt;pre class="coloredcode"&gt;&amp;lt;&lt;span class="tag"&gt;UserControl&lt;/span&gt;&lt;span class="attr"&gt; x:Class=&lt;/span&gt;&lt;span class="attrv"&gt;&amp;quot;SLBindingSetterBug.Page&amp;quot;&lt;/span&gt;
&lt;span class="attr"&gt;    xmlns=&lt;/span&gt;&lt;span class="attrv"&gt;&amp;quot;http://schemas.microsoft.com/winfx/2006/xaml/presentation&amp;quot;&lt;/span&gt; 
&lt;span class="attr"&gt;    xmlns:x=&lt;/span&gt;&lt;span class="attrv"&gt;&amp;quot;http://schemas.microsoft.com/winfx/2006/xaml&amp;quot;&lt;/span&gt; 
&lt;span class="attr"&gt;    Width=&lt;/span&gt;&lt;span class="attrv"&gt;&amp;quot;400&amp;quot;&lt;/span&gt;&lt;span class="attr"&gt; Height=&lt;/span&gt;&lt;span class="attrv"&gt;&amp;quot;300&amp;quot;&lt;/span&gt;&amp;gt;
    &amp;lt;&lt;span class="tag"&gt;Grid&lt;/span&gt;&lt;span class="attr"&gt; x:Name=&lt;/span&gt;&lt;span class="attrv"&gt;&amp;quot;LayoutRoot&amp;quot;&lt;/span&gt;&lt;span class="attr"&gt; Background=&lt;/span&gt;&lt;span class="attrv"&gt;&amp;quot;White&amp;quot;&lt;/span&gt;&amp;gt;
        &amp;lt;&lt;span class="tag"&gt;StackPanel&lt;/span&gt;&amp;gt;
            &amp;lt;&lt;span class="tag"&gt;TextBox&lt;/span&gt;&lt;span class="attr"&gt; Text=&lt;/span&gt;&lt;span class="attrv"&gt;&amp;quot;{Binding MyText, Mode=TwoWay}&amp;quot;&lt;/span&gt; /&amp;gt;
            &amp;lt;&lt;span class="tag"&gt;TextBox&lt;/span&gt;&lt;span class="attr"&gt; Text=&lt;/span&gt;&lt;span class="attrv"&gt;&amp;quot;{Binding MyText, Mode=TwoWay}&amp;quot;&lt;/span&gt; /&amp;gt;
            &amp;lt;&lt;span class="tag"&gt;TextBlock&lt;/span&gt;&lt;span class="attr"&gt; Text=&lt;/span&gt;&lt;span class="attrv"&gt;&amp;quot;{Binding MyText}&amp;quot;&lt;/span&gt; /&amp;gt;
        &amp;lt;/&lt;span class="tag"&gt;StackPanel&lt;/span&gt;&amp;gt;
    &amp;lt;/&lt;span class="tag"&gt;Grid&lt;/span&gt;&amp;gt;
&amp;lt;/&lt;span class="tag"&gt;UserControl&lt;/span&gt;&amp;gt;
&lt;/pre&gt;&amp;nbsp;&amp;nbsp;&lt;p&gt;Page.xaml.cs&lt;/p&gt;&lt;p&gt;&amp;nbsp;&lt;/p&gt;&lt;pre class="coloredcode"&gt;&lt;span class="kwd"&gt;using&lt;/span&gt; System.Windows.Controls;

&lt;span class="kwd"&gt;namespace&lt;/span&gt; SLBindingSetterBug
{
    &lt;span class="kwd"&gt;public&lt;/span&gt; partial &lt;span class="kwd"&gt;class&lt;/span&gt; Page : UserControl
    {
        &lt;span class="kwd"&gt;public&lt;/span&gt; Page()
        {
            InitializeComponent();
            DataContext = &lt;span class="kwd"&gt;new&lt;/span&gt; Document();
        }
    }
}
&lt;/pre&gt;&amp;nbsp;&lt;br /&gt;</description></item></channel></rss>