2
votes

I have a WPF Project with a RibbonWindow as MainWindow and I’m using Catel.

/Views/MainWindow:

public partial class MainWindow : MainWindowBase
{
    public MainWindow()
    {
        InitializeComponent();
    }
}

This MainWindow is derived from MainWindowBase. MainWindowBase is derived from RibbonWindow and implements IDataWindow as described in the Catel documentation.

public class MainWindowBase : RibbonWindow, IDataWindow
{
    private readonly WindowLogic _logic;
    //...
}

The MainWindow is instantiated by StartupUri="/Views/MainWindow.xaml" and the correct MainWindowViewModel is resolved and instantiated.

In the MainWindow I have a content control which is bound to a Property CurrentViewModel in my MainWindowViewModel

<ContentControl DockPanel.Dock="Bottom" Content="{Binding Path=CurrentViewModel}"></ContentControl>

/ViewModels/MainWindowViewModel:

public class MainWindowViewModel : ViewModelBase
{
//..
    public static readonly PropertyData CurrentViewModelProperty = RegisterProperty("CurrentViewModel", typeof(ViewModelBase), null);

    public ViewModelBase CurrentViewModel
    {
        get { return GetValue<ViewModelBase>(CurrentViewModelProperty); }
        set { SetValue(CurrentViewModelProperty, value); }
    }
//..
}

This Property is set to a AddressViewModel which is also derived from ViewModelBase

/ViewModels/AddressViewModel:

public class AddressViewModel : ViewModelBase
{
}

I have an AddressView which is derived from Catel.Windows.Controls.UserControl: /Views/AddressView:

public partial class AddressView : Catel.Windows.Controls.UserControl
{
    public AddressView()
    {
        InitializeComponent();
    }
}

The problem is that the associated AddressView is not resolved and the content control just shows the name of the AddressViewModel.

I also have added a DataTemplate to App.xaml like below, with no effect.

<DataTemplate DataType="x:Type vm:AddressViewModel">
    <view:AddressView />
</DataTemplate>

What am I missing?

Thanks!

1
Shouldn't it be like this: {x:Type vm:AddressViewModel} ? Brackets? - Tony
That's it, Tony! You saved my day! I was sure that it had to be something simple, but not that simple. Unfortunately Visual Studio did not complain about the wrong syntax. Many thanks!! - Stefan
@Tony Please post your comment as answer. - Michi-2142
@Mi.Sharp Ok, why not :) - Tony

1 Answers

2
votes

It seems you basically forget about brackets in the expression. Should look like this:

<DataTemplate DataType="{x:Type vm:AddressViewModel}">