Skip to main content
Home Forums Silverlight Programming Silverlight Controls and Silverlight Toolkit AutoCompletebox: show customer name after Datacontext is changed
4 replies. Latest Post by kobruleht on November 11, 2009.
(0)
kobruleht
Member
161 points
583 Posts
11-05-2009 2:53 PM |
AutoCompleteBox is placed to Usercontrol and its ValueMemberPath is set to entity property:
ValueMemberPath="CustomerName"
UserControl Datacontext is to entity new entity. AutoCompleteBox show empty customer name which is OK.
If other entity is loaded, UserControl DataContext property is assigned to this entity like in code below ChangeDataContext() method.
However AutoCompleteBox still shows empty customer name. How to force AutoCompleteBox to show customer name from DataContext entity ?
Andrus.
partial class Layout : UserControl {
public void ChangeDataContext() {
DataContext = Customer2;
}
yifung
Contributor
3313 points
540 Posts
11-06-2009 8:25 PM |
Did you DataBind or set the ItemsSource of the AutoCompleteBox?
11-07-2009 3:21 PM |
There is no databinding (I set id in SelectionChanged) and ItemsSource is not refreshed. Should I create dummy single-item list for ItemsSource or is there better way ?
Min-Hong...
3503 points
397 Posts
11-11-2009 12:04 AM |
Hi,
You are trying to set the AutoCompleteBox's text when a datacontext is set,aren't you? If that is the case, you can try to bind the text property to the datacontext.
Here is how i do it:
<input:AutoCompleteBox x:Name="ab" Width="100" Height="30" Text="{Binding DataContext.Name,RelativeSource={RelativeSource Self}}"></input:AutoCompleteBox> // MyDataContext's object type has a property name, and here i want to show the name
I tested it ,every time i click i set a new dataContext source. The Text of the ACB changed accordingly.
Best Regards
11-11-2009 2:33 PM |
I tried
Binding b = new Binding(col.BoundPropertyName);b.ValidatesOnExceptions = true;
b.NotifyOnValidationError = true;box.comboBox.SetBinding(AutoCompleteBox.TextProperty, b);
This makes form opening very slow compared to creatign dummy item:
box.comboBox.SelectedItem = new PickListEntity() { DisplayMember = (string)DynamicDataSource.Entity.GetValue(col.BoundPropertyName), ValueMember = DynamicDataSource.Entity.GetValue(col.ValuePropertyName) };