I have used all day to figure out what happens, and why this errormessage is shown when I link to a view with data from db. But is fine, when only viewing some textstring.
 
My solution have 5 projects: TheUI, DAL, Model, ViewModel and Views. When run to curser method I can see that the 3 rows from the db goes fine into the Views (UserControls), but when linking on the UI to the specifc UserControl something goes wrong.
 
I'm pretty sure, there is nothing wrong with DAL and Model, so I'm showing you the 3 other projects.
 
I'm not cable to attach the file. I do not know why the solution zipped is sice 47mb. If You want code for the other projects, just say so.
 
The error is in below line in MainWindow.xaml line 110
  1. "CategoryView" Grid.Column="0" Grid.ColumnSpan="3" Grid.Row="2" />  
Best regards
Simsen :)
ViewModel.Account.CategoryViewModel:
  1. using System;  
  2. using System.Collections.Generic;  
  3. using System.Text;  
  4. using System.Collections.ObjectModel;  
  5. using Model.Account;  
  6. using DAL.Account;  
  7. namespace ViewModel.Account  
  8. {  
  9. public class CategoryViewModel  
  10. {  
  11. private Category _selectedCategory;  
  12. public MyICommand DeleteCommand { get; set; }  
  13. public Category SelectedCategory  
  14. {  
  15. get  
  16. {  
  17. return _selectedCategory;  
  18. }  
  19. set  
  20. {  
  21. _selectedCategory = value;  
  22. DeleteCommand.RaiseCanExecuteChanged();  
  23. }  
  24. }  
  25. public CategoryViewModel()  
  26. {  
  27. LoadCategories();  
  28. DeleteCommand = new MyICommand(OnDelete, CanDelete);  
  29. }  
  30. public ObservableCollection Categories { get; set; }  
  31. public void LoadCategories()  
  32. {  
  33. DalCategory dalCategory = new DalCategory();  
  34. ObservableCollection dalCategories = dalCategory.GetCategories();  
  35. Categories = dalCategories;  
  36. }  
  37. #region Delete  
  38. private void OnDelete()  
  39. {  
  40. Categories.Remove(SelectedCategory);  
  41. }  
  42. private bool CanDelete()  
  43. {  
  44. return SelectedCategory != null;  
  45. }  
  46. #endregion  
  47. }  
  48. }
Views.CategoryView.Account.CategoryView.xaml:
  1. "Views.Account.CategoryView"  
  2. xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"  
  3. xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"  
  4. xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"  
  5. xmlns:d="http://schemas.microsoft.com/expression/blend/2008"  
  6. xmlns:viewModel = "clr-namespace:ViewModel.Account;assembly=ViewModel"  
  7. xmlns:data = "clr-namespace:Model.Account;assembly=Model"  
  8. mc:Ignorable="d"  
  9. d:DesignHeight="450" d:DesignWidth="800">  
  10.   
  11. "Horizontal">  
  12. "{Binding Mode=OneWay}">  
  13.   
  14. "Horizontal">  
  15. "{Binding CategoryId}" />  
  16. "{Binding CategoryName}" />  
  17. "{Binding CategoryIsGlobal}" />  
  18. "{Binding ProjectId}" />  
  19. "{Binding IsObsolete}" />  
  20.   
  21.   
  22.   
  23.   
  24.   
  25.   
Views.CategoryView.Account.CategoryView.xaml.cs:
  1. using System;  
  2. using System.Collections.Generic;  
  3. using System.Linq;  
  4. using System.Text;  
  5. using System.Threading.Tasks;  
  6. using System.Windows;  
  7. using System.Windows.Controls;  
  8. using System.Windows.Data;  
  9. using System.Windows.Documents;  
  10. using System.Windows.Input;  
  11. using System.Windows.Media;  
  12. using System.Windows.Media.Imaging;  
  13. using System.Windows.Navigation;  
  14. using System.Windows.Shapes;  
  15. namespace Views.Account  
  16. {  
  17. ///   
  18. /// Interaction logic for CategoryView.xaml  
  19. ///   
  20. public partial class CategoryView : UserControl  
  21. {  
  22. public CategoryView()  
  23. {  
  24. InitializeComponent();  
  25. this.DataContext = new ViewModel.Account.CategoryViewModel();  
  26. string HereICheckTheDataContextAndItHas3Rows = "";  
  27. }  
  28. }  
  29. }  
AnsiBug.MainWindow.xaml:
  1. "http://schemas.syncfusion.com/wpf" x:Name="AnsiBug" x:Class="AnsiBug.MainWindow"  
  2. xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"  
  3. xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"  
  4. xmlns:d="http://schemas.microsoft.com/expression/blend/2008"  
  5. xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"  
  6. xmlns:local="clr-namespace:AnsiBug"  
  7. xmlns:views = "clr-namespace:Views.Account;assembly=Views"  
  8. mc:Ignorable="d"  
  9. Title="MainWindow" Height="800" Width="1200" HorizontalAlignment="Center" VerticalAlignment="Center" WindowStartupLocation="CenterScreen">  
  10.   
  11.   
  12.   
  13. "cmBtnReports" >  
  14. "BtnTextReports" Header="Tekst rapporter" />  
  15. "BtnReporsMyBugs" Header="Mine fejl" />  
  16. "BtnReporsNewBugs" Header="Nye fejl" />  
  17. "BtnReporsAllBugs" Header="Alle fejl" />  
  18. "BtnReporsClosedBugs" Header="Lukkede fejl" />  
  19. "BtnReporsNoAssignedBugs" Header="Ikke tildelte fejl" />  
  20.   
  21.   
  22.   
  23. "cmBtnAdministration" >  
  24. "BtnShowUsers" Header="Vis brugere" />  
  25. "BtnAddUser" Header="Tilføj bruger" />  
  26. "BtnEditAccount" Header="Ret konto" />  
  27. "BtnShowProjects" Header="Vis projekter" />  
  28. "BtnAddProject" Header="Tilføj projekt" />  
  29. "BtnManagement" Header="Vedligeholdelse" />  
  30.   
  31.   
  32.   
  33. "cmBtnPreferences" >  
  34. "BtnMyInfo" Header="Min info" />  
  35.   
  36.   
  37.   
  38. "cmBtnLists" >  
  39. "BtnMyBugs" Header="Mine fejl" />  
  40. "BtnNewBugs" Header="Nye fejl" />  
  41. "BtnAllBugs" Header="Alle fejl" />  
  42. "BtnUnAssignedBugs" Header="Ikke tildelte fejl" />  
  43. "BtnClosedBugs" Header="Lukkede fejl" />  
  44.   
  45.   
  46.   
  47. "cmBtnProjects" >  
  48. "BtnDashBoard" Header="Dashboard" />  
  49. "BtnNewBug" Header="Ny fejl" />  
  50.   
  51.   
  52.   
  53.   
  54.