0

I'm trying to learn Catel MVVM by getting the simplest of bare bones example of Catel to work on VS Express 2012 and keep getting an error. I think my problem lies in my "using" statements, references, or the header in my XAML. An auto-generated file writes the offending line as shown below in MainWindow.g.cs The code files are very short, so I've included them.

The model, viewmodel, and view are separated into three projects all under one solution.

  • Model- blank for now
  • ViewModel -MainWindowViewModel (no properties yet)
  • View -MainWindow.xmal, MainWindow.xmal.cs (no controls or properties yet)

    I keep getting the following warning with an accompanying error:

    The type 'Catel.Windows.DataWindow' in 'c:...\MainWindow.g.cs' conflicts with the imported type 'Catel.Windows.DataWindow' in 'c:...\Catel.MVVM.dll'. Using the type defined in 'c:...\MainWindow.g.cs'.

    and the error:

    Catel.Windows.DataWindow < ViewModels.MainWindowViewModel > is obsolete: 'Please use 'Catel.Windows.DataWindow' instead. Will be removed in version '4.0'.' C:...\MyFirstCatel\obj\Debug\MainWindow.g.cs

    MainWindow.xaml

    <Windows:DataWindow 
            x:Class="Catel.Windows.DataWindow"
            xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
            xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"           
            xmlns:MainWindowViewModel="clr-namespace:ViewModels"
            xmlns:Windows="clr-namespace:Catel.Windows;assembly=Catel.MVVM"
           x:TypeArguments="MainWindowViewModel:MainWindowViewModel"
            Title="MainWindow" Height="350" Width="525">
        <Grid>
            <TextBlock>Hello world!</TextBlock>
        </Grid>
    </Windows:DataWindow>
    

    MainWindow.xaml.cs

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    using System.Threading.Tasks;
    using System.Windows;
    using System.Windows.Controls;
    using System.Windows.Data;
    using System.Windows.Documents;
    using System.Windows.Input;
    using System.Windows.Media;
    using System.Windows.Media.Imaging;
    using System.Windows.Navigation;
    using System.Windows.Shapes;
    using Catel.Windows;
    
    
    namespace MyFirstCatel
    {
    
        public partial class MainWindow : Catel.Windows.DataWindow
        {
            public MainWindow() 
            {
                InitializeComponent();
            }
        }
    }
    

    MainWindowViewModel.cs

    using System.Windows;
    using Catel.MVVM;
    
    namespace ViewModels
    {
        public class MainWindowViewModel : ViewModelBase
        {
            public MainWindowViewModel()
                : base()
            {
            }
    
            public override string Title { get { return "View model title"; } }
    
            public string Slug
            {
                get { return GetValue<string>(SlugProperty); }
                set { SetValue(SlugProperty, value); }
            }
    
            public static readonly Catel.Data.PropertyData SlugProperty = RegisterProperty("Slug", typeof(string), null);
    
        }
    }
    

    And in MainWindow.g.cs

    namespace Catel.Windows {
        public partial class DataWindow : Catel.Windows.DataWindow<ViewModels.MainWindowViewModel>, System.Windows.Markup.IComponentConnector 
    {
         private bool _contentLoaded;
         ... code removed for post ....
    
    }
    

    }

  • 1 Answers1

    0

    There is only one thing that is wrong. Inside your xaml definition you still use the old way of specifying the vm type. Remove the x:TypeArguments and the error should go away.

    Geert van Horrik
    • 5,689
    • 1
    • 18
    • 32
    • WOW! Thank you so much for your help! I'm the same guy that emailed you about VS Express templates. I made the following changes: Deleted x:TypeArguments and added But now I get a circular reference in MainWindow.g.cs: Error 1 Circular base class dependency involving 'Catel.Windows.DataWindow' and 'Catel.Windows.DataWindow' C:\...\MainWindow.s – Johnny Beatniks Jun 08 '13 at 21:50
    • I got a little further: I changed the x:Class="MyFirstCatel.MainWindow" Now I get another error, Invocation of constructor on type, "MyFirstCatel.MainWindow" that matches the specified binding constraints threw an exception... – Johnny Beatniks Jun 08 '13 at 22:14
    • Now I get"DataWindow.cs not found You need to find DataWindow.cs to view the source for the current call stack frame." – Johnny Beatniks Jun 08 '13 at 23:58
    • I've tried to re-write the project more carefully. I get an error on the constructor of the DataWindow. public MainWindow() : base() – Johnny Beatniks Jun 09 '13 at 02:47
    • Just remove the DataContext part as well. Catel does this all automatically. Can you give more details about the error? – Geert van Horrik Jun 09 '13 at 03:34
    • I've been reading CTL-53 under your issue tracker sight. I want to restate that **my model, view, and viewmodel are in separate projects**. At this point I think my problem is NamingConvetntions. Catel.MVVM.ViewModelLocator viewModelLocator = new Catel.MVVM.ViewModelLocator(); viewModelLocator.NamingConventions.Add("ViewModels"); AppDomain.CurrentDomain.PreloadAssemblies(typeof(App).Assembly.GetDirectory()); – Johnny Beatniks Jun 09 '13 at 20:51
    • The error I'm getting is: An unhandled exception of type 'System.Windows.Markup.XamlParseException' occurred in PresentationFramework.dll Additional information: 'The invocation of the constructor on type 'Views.MainWindow' that matches the specified binding constraints threw an exception.' Line number '6' and line position '8'. – Johnny Beatniks Jun 09 '13 at 20:59
    • I downloaded [link]http://catel.codeplex.com/Download/AttachmentDownload.ashx?ProjectName=catel&WorkItemId=7094&FileAttachmentId=351393 and will have a look at it this evening. – Johnny Beatniks Jun 09 '13 at 21:10
    • Bam! Got It! The code below in the MainWindow: . 'protected override System.Type GetViewModelType() { return typeof(ViewModels.MainWindowViewModel); }' – Johnny Beatniks Jun 10 '13 at 03:32
    • Great! Thanks for letting us know. – Geert van Horrik Jun 10 '13 at 04:24