Hi team,
this is very cool control, but I am for some reason unable to bind SelectedItems to my VM.
<ig:XamComboEditor EmptyText="Select Region..." IsEnabled="{Binding ElementName=_regionSearch, Path=IsChecked}" Grid.Column="1" SelectedItem="{Binding SelectedRegions, NotifyOnSourceUpdated=True, NotifyOnTargetUpdated=True, UpdateSourceTrigger=PropertyChanged}" IsEditable="False" CheckBoxVisibility="Visible" AllowMultipleSelection="True" ItemsSource="{Binding Regions}"/>
VM
public ObservableCollection<IdentifierDetail> SelectedRegions{
get { return _selectedRegions; }
set {
if (_selectedRegions == null
)
_selectedRegions = new ObservableCollection<IdentifierDetail>();
_selectedRegions = value;
OnPropertyChanged("SelectedRegions");
}}
public class IdentifierDetail { private string idField; private string nameField;
public string Id { get { return this.idField; } set { this.idField = value; } }
public string Name { get { return this.nameField; } set { this.nameField = value; } }
public override string ToString() { if (!string.IsNullOrEmpty(Name)) return Name; return string.Empty; }
public override int GetHashCode() { return ToString().GetHashCode(); }
public override bool Equals(object obj) { IdentifierDetail other = (obj as IdentifierDetail); if (other != null && other.Id != null && other.Name != null) { return Id.Equals(other.Id) && Name.Equals(other.Name); } return false; }
}
Please help me.
thanks
Hello Anant,
Thank you for your post. I have been looking into it and I created a sample project for you with the functionality you want. Basically the SelectedRegions collection should be ObservableCollection of objects and the SelectedItems Property of the XamComboEditor should be bind to a Source, not via the DataContext. Please let me know if this helps you or you have further questions on this matter.
Looking forward for your reply.
I tried your solution and I am getting this error in your solution. When I deselect the checkbox. it thow below exception
System.NullReferenceException was unhandled Message=Object reference not set to an instance of an object. Source=InfragisticsWPF4.DataManager.v14.1 StackTrace: at Infragistics.DataManagerBase.ResolveFromPropertyPath(String propertyPath, Object data, Boolean returnValue) at Infragistics.DataManagerBase.ResolveValueFromPropertyPath(String propertyPath, Object data) at Infragistics.Controls.Editors.ComboEditorBase`2.SelectedItems_CollectionChanged(Object sender, NotifyCollectionChangedEventArgs e) at System.Collections.Specialized.NotifyCollectionChangedEventHandler.Invoke(Object sender, NotifyCollectionChangedEventArgs e) at System.Collections.ObjectModel.ObservableCollection`1.OnCollectionChanged(NotifyCollectionChangedEventArgs e) at System.Collections.ObjectModel.ObservableCollection`1.RemoveItem(Int32 index) at System.Collections.ObjectModel.Collection`1.Remove(T item) at Infragistics.Controls.Editors.ComboEditorBase`2.UnselectItem(Object data) at Infragistics.Controls.Editors.ComboEditorBase`2.UnselectItem(T item) at Infragistics.Controls.Editors.ComboEditorBase`2.OnComboEditorItemClicked(T comboEditorItem) at Infragistics.Controls.Editors.ComboEditorItemControl.OnMouseLeftButtonDown(MouseButtonEventArgs e) at System.Windows.UIElement.OnMouseLeftButtonDownThunk(Object sender, MouseButtonEventArgs e) at System.Windows.Input.MouseButtonEventArgs.InvokeEventHandler(Delegate genericHandler, Object genericTarget) at System.Windows.RoutedEventArgs.InvokeHandler(Delegate handler, Object target) at System.Windows.RoutedEventHandlerInfo.InvokeHandler(Object target, RoutedEventArgs routedEventArgs) at System.Windows.EventRoute.InvokeHandlersImpl(Object source, RoutedEventArgs args, Boolean reRaised) at System.Windows.UIElement.ReRaiseEventAs(DependencyObject sender, RoutedEventArgs args, RoutedEvent newEvent) at System.Windows.UIElement.OnMouseDownThunk(Object sender, MouseButtonEventArgs e) at System.Windows.Input.MouseButtonEventArgs.InvokeEventHandler(Delegate genericHandler, Object genericTarget) at System.Windows.RoutedEventArgs.InvokeHandler(Delegate handler, Object target) at System.Windows.RoutedEventHandlerInfo.InvokeHandler(Object target, RoutedEventArgs routedEventArgs) at System.Windows.EventRoute.InvokeHandlersImpl(Object source, RoutedEventArgs args, Boolean reRaised) at System.Windows.UIElement.RaiseEventImpl(DependencyObject sender, RoutedEventArgs args) at System.Windows.UIElement.RaiseTrustedEvent(RoutedEventArgs args) at System.Windows.UIElement.RaiseEvent(RoutedEventArgs args, Boolean trusted) at System.Windows.Input.InputManager.ProcessStagingArea() at System.Windows.Input.InputManager.ProcessInput(InputEventArgs input) at System.Windows.Input.InputProviderSite.ReportInput(InputReport inputReport) at System.Windows.Interop.HwndMouseInputProvider.ReportInput(IntPtr hwnd, InputMode mode, Int32 timestamp, RawMouseActions actions, Int32 x, Int32 y, Int32 wheel) at System.Windows.Interop.HwndMouseInputProvider.FilterMessage(IntPtr hwnd, WindowMessage msg, IntPtr wParam, IntPtr lParam, Boolean& handled) at System.Windows.Interop.HwndSource.InputFilterMessage(IntPtr hwnd, Int32 msg, IntPtr wParam, IntPtr lParam, Boolean& handled) at MS.Win32.HwndWrapper.WndProc(IntPtr hwnd, Int32 msg, IntPtr wParam, IntPtr lParam, Boolean& handled) at MS.Win32.HwndSubclass.DispatcherCallbackOperation(Object o) at System.Windows.Threading.ExceptionWrapper.InternalRealCall(Delegate callback, Object args, Int32 numArgs) at MS.Internal.Threading.ExceptionFilterHelper.TryCatchWhen(Object source, Delegate method, Object args, Int32 numArgs, Delegate catchHandler) at System.Windows.Threading.Dispatcher.InvokeImpl(DispatcherPriority priority, TimeSpan timeout, Delegate method, Object args, Int32 numArgs) at MS.Win32.HwndSubclass.SubclassWndProc(IntPtr hwnd, Int32 msg, IntPtr wParam, IntPtr lParam) at MS.Win32.UnsafeNativeMethods.DispatchMessage(MSG& msg) at System.Windows.Threading.Dispatcher.PushFrameImpl(DispatcherFrame frame) at System.Windows.Threading.Dispatcher.PushFrame(DispatcherFrame frame) at System.Windows.Application.RunDispatcher(Object ignore) at System.Windows.Application.RunInternal(Window window) at System.Windows.Application.Run(Window window) at System.Windows.Application.Run() at WpfApplication1.App.Main() in \\msad\root\ap\apbo\mi\users\anantgyg\visual studio 2010\Projects\WpfApplication1\WpfApplication1\obj\x86\Debug\App.g.cs:line 0 at System.AppDomain._nExecuteAssembly(RuntimeAssembly assembly, String[] args) at System.AppDomain.ExecuteAssembly(String assemblyFile, Evidence assemblySecurity, String[] args) at Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly() at System.Threading.ThreadHelper.ThreadStart_Context(Object state) at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean ignoreSyncCtx) at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state) at System.Threading.ThreadHelper.ThreadStart() InnerException: