this link(http://ko.infragistics.com/community/blogs/devin_rader/archive/2011/06/01/using-behaviors-to-synchronize-selected-items-of-infragistics-silverlight-controls-to-a-viewmodel.aspx) shows how to synchronize multipleSelection from the UI side.
but if i initialize the SelectedCustomers property by adding two customer, run it, the UI side doesn't show the information.
now i can get the multipleSelection itmes' value by this following way,
1. define the SelectedItemsValues
public static readonly DependencyProperty SelectedItemsValuesProperty = DependencyProperty.Register("SelectedItemsValues", typeof(List), typeof(XamComboEditorSelectedItemsBehavior), new PropertyMetadata(OnSelectedItemsPropertyChanged)); public List SelectedItemsValues
2. in the Combobox.SelectedItems.CollectionChanged event, foreach the items to get the value what i want. each item is ICityDimension type.
UnsubscribeFromEvents(); Transfer(Combobox.SelectedItems, SelectedItems as IList); List results= new List(); foreach (object tmp in Combobox.SelectedItems) { convert.Add(((ICityDimension)val).Description); } SelectedItemsValues = convert; SubscribeToEvents();
my behavior class is as follows:::::
public class XamComboEditorSelectedItemsBehavior : Behavior { private XamComboEditor Combobox { get { return AssociatedObject as XamComboEditor; } }
public static readonly DependencyProperty SelectedItemsProperty = DependencyProperty.Register("SelectedItems", typeof(INotifyCollectionChanged), typeof(XamComboEditorSelectedItemsBehavior), new PropertyMetadata(OnSelectedItemsPropertyChanged)); public INotifyCollectionChanged SelectedItems { get { return (INotifyCollectionChanged)GetValue(SelectedItemsProperty); } set { SetValue(SelectedItemsProperty, value); } }
public static readonly DependencyProperty SelectedItemsValuesProperty = DependencyProperty.Register("SelectedItemsValues", typeof(List), typeof(XamComboEditorSelectedItemsBehavior), new PropertyMetadata(OnSelectedItemsPropertyChanged)); public List SelectedItemsValues { get { return (List)this.GetValue(SelectedItemsValuesProperty); } set { this.SetValue(SelectedItemsValuesProperty, value); } }
private static void OnSelectedItemsPropertyChanged(DependencyObject target, DependencyPropertyChangedEventArgs args) { var collection = args.NewValue as INotifyCollectionChanged; if (collection != null) { collection.CollectionChanged += ((XamComboEditorSelectedItemsBehavior)target).ContextSelectedItems_CollectionChanged; } }
protected override void OnAttached() { base.OnAttached();
Combobox.SelectedItems.CollectionChanged += new NotifyCollectionChangedEventHandler(SelectedItems_CollectionChanged); //Combobox.Loaded += new RoutedEventHandler(Combobox_Loaded); }
void Combobox_Loaded(object sender, RoutedEventArgs e) { throw new NotImplementedException(); }
void ContextSelectedItems_CollectionChanged(object sender, NotifyCollectionChangedEventArgs e) { UnsubscribeFromEvents();
Transfer(SelectedItems as IList, Combobox.SelectedItems);
SubscribeToEvents(); }
void SelectedItems_CollectionChanged(object sender, System.Collections.Specialized.NotifyCollectionChangedEventArgs e) { UnsubscribeFromEvents(); Transfer(Combobox.SelectedItems, SelectedItems as IList); List convert = new List(); foreach (object tmp in Combobox.SelectedItems) { convert.Add(((ICityDimension)tmp).Description); } SelectedItemsValues = convert; SubscribeToEvents(); }
private void SubscribeToEvents() { Combobox.SelectedItems.CollectionChanged += SelectedItems_CollectionChanged;
if (SelectedItems != null) { SelectedItems.CollectionChanged += ContextSelectedItems_CollectionChanged; } }
private void UnsubscribeFromEvents() { Combobox.SelectedItems.CollectionChanged -= SelectedItems_CollectionChanged;
if (SelectedItems != null) { SelectedItems.CollectionChanged -= ContextSelectedItems_CollectionChanged; } }
public static void Transfer(IList source, IList target) { if (source == null || target == null) return;
target.Clear();
foreach (var tmp in source) { target.Add(tmp); } } }
i created the loaded event in the behaviors class, foreach the ComboEditorItem to compare the SelectedItemsValue, but still only get one item to show event there are many than one item.
then i loop the ComboEditorItem to compare the SelectedItems, but no text show.
anyone can give me some clue?
void Combobox_Loaded(object sender, RoutedEventArgs e) { foreach (ComboEditorItem item in Combobox.Items) { if(SelectedItemsValues.Contains(((ILookUpDimension)item.Data).Code)) { item.IsSelected=true; } } // throw new NotImplementedException(); }
Hello wobudongta,
I am just checking if you got this worked out, or you still require any assistance, or clarification on the matter.
If this is what you were looking for please verify the answer so it helps other users as well.