Silverlight 3 AutocompleteBox.text is not updated
In silverlight 3 I am doing something like :
//currentDataForm.itemssource = currentCollisionDisplay;
//<input:AutoCompleteBox Width="74" x:Name="InvolvedCnt" Text="{Binding involvedCnt, Mode=TwoWay}"
...
for (int i = 0; i < driverNums; i++)
{
AddCollisionVehicle_Click(null, null);
}
...
private void AddCollisionVehicle_Click(object sender, RoutedEventArgs e)
{
currentCollisionDisplay.involvedCnt ++;
(df_collision.FindNameInContent("InvolvedCnt") as AutoCompleteBox).Text = currentCollisionDisplay.involvedCnt.ToString();
(df_collision.FindNameInContent("InvolvedCnt") as AutoCompleteBox).UpdateLayout();
string testString = (df_collision.FindNameInContent("InvolvedCnt") as AutoCompleteBox).Text;
}
so the initial value of the autocompletebox is "1". if driverNums = 1开发者_StackOverflow社区 then the autocompletebox.text is 2.. which is correct but if driverNums = 2 then the autocompletebox.text is 2.. which is wrong.
I changed the autocompletebox text field within an array, but this is not updated properly.. does anybody know how to fix this issue?
Strange thing is if i check testString variable, the value is correct..
This appears to be a known issue. See http://forums.silverlight.net/forums/p/199616/519232.aspx
A workaround that worked in my application is to clear out the Text property and then set it again using Dispatcher.BeginInvoke, i.e. something like this:
autoCompleteBox.Text = null;
Dispatcher.BeginInvoke(() =>
autoCompleteBox.Text = currentCollisionDisplay.involvedCnt.ToString());
I've only done this in one scenario so I don't know for sure if it'll work for you. My application also used bindings (I called ClearValue and then SetBinding).
You need to use the method "ValueMemberBrinding"
<toolkit:AutoCompleteBox x:Name="InvolvedCnt" ValueMemberBinding="{Binding Name}"/>
精彩评论