Problem 1: In the following code I expect the grid to display the value "Digital" in the ComboBoxColumn of the first row. Instead, I have an empty cell.
Problem 2: When I select "Digital" and tab out from the cell I receive the exception at the bottom.
public class ResourceTypes : ObservableCollection
{ public ResourceTypes() { this.Add(new ResourceTypeElement {Name = "Printed"}); this.Add(new ResourceTypeElement {Name = "Digital"}); }}
public class ResourceTypeElement : INotifyPropertyChanged{ private string name; public string Name { get { return this.name; } set { if (this.name != value) { this.name = value; } } }
public event PropertyChangedEventHandler PropertyChanged;}
public class Resource: INotifyPropertyChanged{ public ResourceTypeElement Type { get; set; }
public Resource() { this.Type = new ResourceTypeElement { Name = "Digital" }; }
public class ResourceDetailViewModel { public ObservableCollection Resources { get; set; }
public ResourceDetailViewModel() { this.Resources = new ObservableCollection; this.Resources.Add(new Resource()); }
}Xaml:
AutoGenerateColumns="false" ColumnWidth="*"> IsEnterKeyEditingEnabled="True" IsF2EditingEnabled="True" IsMouseActionEditingEnabled="SingleClick" IsOnCellActiveEditingEnabled="True" /> ItemsSource="{Binding Source={StaticResource ResourceTypes}}" SelectedValuePath="Name" DisplayMemberPath="Name" AllowEditingValidation="False"/> The exception I receive when I select a combo box item and tab out:
System.Windows.Markup.XamlParseException occurred Message= [Line: 0 Position: 0] LineNumber=0 LinePosition=0 StackTrace: by MS.Internal.XcpImports.CheckHResult(UInt32 hr) InnerException: System.Collections.Generic.KeyNotFoundException Message=The given key was not present in the dictionary. StackTrace: by System.Collections.Generic.Dictionary`2.get_Item(TKey key) by System.Windows.ResourceManagerWrapper.GetResourceForUri(Uri xamlUri, Type componentType) InnerException:
Solved this problem by changing the type of Resource.Type from ResourceTypeElement to string.