Issue with View and ViewModel binding

Nov 5, 2014 at 8:33 AM
Edited Nov 5, 2014 at 8:35 AM
Hi all!

I am trying to create an application on the basis of the WAF framework following the MVVM pattern. Currently, my solution consists of two projects (each equipped with MEF and MAF references):

*.Application (holding controllers and viewmodels)
*.Presentation (holding the actual view files)

I am creating the binding between view and viewmodel via the ViewModel interface. Further, all classes are made available via the MEF framework inside the App.xaml.cs file. Here, the controller is also initialized. In the easiest case, i want to show a string value in a label of the main window.

Here is the problem: If i start the application, the value of the second label only shows the fallback value, but the get method of the property is being called peroperly (checked via debugging mode). The binding between View and ViewModel seems to be correct - if i change the binding path in the xaml to a non existent property, i get an output that the property can not be found in the ViewModel. My impression is that there could be a problem with the events for view updating? Any suggestions on this strange behaviour?

Thank you in advance for your help!

Here is the excerptof the ViewModel:
    [Export]
    public class MainWindowViewModel : ViewModel<IMainWindowView>
    {
        private string _labelContent;
        public string LabelContent
        {
            get { return _labelContent; }
            set { SetProperty(ref _labelContent, value); }
        }
    
        [ImportingConstructor]
        public MainWindowViewModel(IMainWindowView view) : base(view)
        {
        }
    }
Here is the excerpt of the controller:
    [Export(typeof(IMainWindowController))]
    public class MainWindowController : IMainWindowController
    {
        private MainWindowViewModel _mainWindowViewModel;
        public MainWindowViewModel MainWindowViewModel
        {
            get { return _mainWindowViewModel; }
            set { _mainWindowViewModel = value; }
        }
    
        [ImportingConstructor]
        public MainWindowController(MainWindowViewModel mainWindowViewModel)
        {
            _mainWindowViewModel = mainWindowViewModel;
        }
    
        public void Initialize()
        {
            _mainWindowViewModel.LabelContent = "stfu";
        }
    }
The view interface:
    public interface IMainWindowView : IView
    {
    }
And the view itself:
    [Export(typeof(IMainWindowView))]
    public partial class MainWindow : Window, IMainWindowView
    {
        public MainWindow()
        {
            InitializeComponent();
        }
    }
    <Window x:Class="Volkswagen.CaSys.Redesign.Presentation.MainWindow"
            xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
            xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
            Title="MainWindow" Height="350" Width="525">
        <StackPanel>
            <Label Content="Test" />
            <Label Name="MyLabel" Content="{Binding Path=LabelContent, FallbackValue=Fallback}" />
        </StackPanel>
    </Window>
Nov 5, 2014 at 9:45 PM
Where is code that calls Initialize()?
Nov 6, 2014 at 8:21 AM
The init as well as the dependency injection stuff was handled inside the App.xaml.cs. The issue is already solved - the problem was the StartupUri. See the stackoverflow post:

http://stackoverflow.com/questions/26753219/view-values-are-not-inserted-but-retrieved-from-viewmodel
Marked as answer by fstegmaier on 11/6/2014 at 1:22 AM