c# - InvalidCast exception when clearing ObservableCollection bound to a list view, can not cast MS.Internal.NamedObject -
I have a ListView that uses a Gridwu and it is bound to an observation collection. On load I populate the collection and appears in the UI as expected. The problem occurs when I try to manipulate observation supervision later; If I call RemoveAt (n) or Clear () on the archive, then I get an invalid cast exception that can not convert MS.Internal.NamedObject to the type of object stored in the archive.
I've read Detagred, he can not find any reference to the object designated with me a list of names uses object designated for connecting lines, though. Why this exception is happening and how can I fix the original problem without resorting to holding / blocking around each clean or removeAt
exception?
Unable to 'user' to type to cast object { "type 'MS.Internal.NamedObject'."} Start ListView
<> pre & lt; ListView Name = "listViewUsers" Grid.Row = "0" ItemsSource = "{Binding Path = user}" GridViewColumnHeader.Click = "GridViewHeader_Click" & gt; & Lt; ListView.Resources & gt; & Lt; Datamapplet X: Key = "User Control" & gt; & Lt; StackPanel Orientation = "Horizontal" & gt; & Lt; Button cmd: Click.Command = "{Binding Path = Model.UserService.DeleteUserCommand, RelativeSource = {RelativeSource FindAncestor, AncestorType = {x: Type UserControl}}}" cmd: Click.CommandParameter = "{Binding Path = content, RelativeSource = {RelativeSource FindAncestor, AncestorType = {x: Type ListViewItem}}} "& gt; Remove & lt; / Button & gt; & Lt; Button cmd: Click.Command = "{Binding Path = Model.EditUserCommand, RelativeSource = {RelativeSource FindAncestor, AncestorType = {x: Type UserControl}}}" cmd: Click.CommandParameter = "{Binding Path = content, RelativeSource = {relative Source FindAncestor, ancestor type = {x: type list ViewItem}}} "& gt; Edit & lt; / Button & gt; & Lt; / StackPanel & gt; & Lt; / DataTemplate & gt; & Lt; DataTemplate x: key = "IsEnabledTemplate" & gt; & Lt; Check box IsChecked = "{IsInabled Binding}" IsEnabled = "False" /> & Lt; / DataTemplate & gt; & Lt; Style TargetType = "{x: Type List ViewItem}" & gt; & Lt; EventSetter Event = "MouseDoubleClick" Handler = "ListViewUserD DoubleClick" /> & Lt; / Style & gt; & Lt; /ListView.Resources> & Lt; ListView.View & gt; & Lt; GridView & gt; & Lt; GridViewColumn CellTemplate = "{StaticResource UserControl}" /> & Lt; GridViewColumn header = "enabled" Width = "Auto" cell template = "{static resource IsEnabledTemplate}" /> & Lt; GridViewColumn Header = "User ID" DisplayMemberBinding = "{Binding ID}" /> & Lt; GridViewColumn Header = "First Name" width = "Auto" DisplayMemberBinding = "{Binding FirstName}" /> & Lt; GridViewColumn Header = "Last Name" width = "Auto" DisplayMemberBinding = "{Binding LastName}") & gt; & Lt; GridViewColumn header = "user name" width = "auto" DisplayMemberBinding = "{binding user name}" /> & Lt; / GridView & gt; & Lt; /ListView.View> & Lt; / ListView & gt; Code (heavy paused): Public class UserService: IUserService {Private Readonly Illogger faq_logger; Private readonly event aggregator _ avent aggregator; Personal observable collection & lt; EnterpriseUser & gt; _users; Public User Service (Illogger FAQ Logger, Event Agent Exjector) {_users = New Observation Collection & lt; Users & gt; (); } Edit public supervision & lt; EnterpriseUser & gt; User {get {return_user; }} Public Zero DeleteUserCommand_Execute (user) {try {bool success = DeleteUser (user); If (! Success) {_logger.Log (string.Format ("enable user to delete: {0}", user.ToString ()), category debug, priority. } And {_logger.Log (string.Format ("User deleted: {0}", user.ToString ()), category debug, priority .a); } the user. Remove (user); } Hold (exception e) {_logger.Log (String.Format ("An exception occurred when trying to delete the user: {0}", e.Message), category. Exception, priority. }}}
Comments
Post a Comment