Search code examples
wpfmvvmprismmef

Binding images to the background


In my WPF project I am using Prism + MEF + MVVM.

In Main Window (I mean Shell.xaml) there has to be a background (image or .wmv file). But this has to be able to change any time (Changes will occurred with view changes). Some views has image, some has movie. I could use images as the background of Views in Modules. But movie files are not proper. While changing, they all start from beginning. I want it to continue if movie is same as the previous view background movie.

In Internet I couldn't found any source/problem about this.

Is there any one who could help me?


Solution

  • I would store the Background in the ParentViewModel, and be sure to only fire the PropertyChanged event if the value has changed.

    public object WindowBackground
    {
        get {return _windowBackground; }
        set
        {
            if (_windowBackground != value)
            {
                _windowBackground = value;
                RaisePropertyChanged("WindowBackground");
            }
        }
    }
    

    You can then use something like Prism's EventAggregator to fire a BackgroundChangeEvent which the parent ViewModel can subscribe to, so all ViewModels can update the background.