Quantcast
Channel: Silverlight Issue Tracker Rss Feed
Viewing all articles
Browse latest Browse all 801

Commented Issue: AutoCompleteBox.SearchText is not cleared when SelectedItem is set to null [8278]

$
0
0
<p>When I use AutoCompleteBox in MVVM scenario I bind SelectedItem to a ViewModel. In the following scenario SearchText is shown in TextBox part instead of expected empty string:</p>
<p>&#160;</p>
<p>1. User enters something in AutoCompleteBox (say &quot;john&quot;) and then selects an item from dropdown (say &quot;John Smith&quot;).</p>
<p>2. Later my code sets null to a ViewModel property to which AutoCompleteBox.SelectedItem is bound.</p>
<p>3. AutoCompleteBox shows old SearchText (&quot;john&quot;) instead of expected empty string.</p>
<p>&#160;</p>
<p>I'm aware of workaround of setting Text=string.Empty before setting SelectedItem=null. This workaournd can even be implemented in MVVM by having Text bound to a special VM property, but this is very ugly in my opinion.</p>
<p>&#160;</p>
<p>I also tried to subclass the AutoCompleteBox to override the bogus behavior, but all required methods and properties are either private or non-virtual, so I was not able to fix this by subclassing too.</p>
Comments: ** Comment from web user: jcc74 **

I found a workaround for this:

this.SelectionChanged += (sender, e) =>
{
System.Windows.Controls.AutoCompleteBox box = sender as System.Windows.Controls.AutoCompleteBox;
if (box.IsNotNull())
{
if (box.SelectedItem.IsNull())
{
//Clear displayed text when SelectedItem is cleared
box.Text = string.Empty;
}
box.IsDropDownOpen = false;
}
};

But my problem is the following:
When SelectedItem is bound at the loading event, the Text is not, and no data displayed in the ACB...
When do you think it could be fixed please? Kind of annoying too.

thank you.


Viewing all articles
Browse latest Browse all 801

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>