1

I have a window which is displaying a a flowdocument binded to a richtextbox in the view. To make this document I use collections from a a different ViewModel.

The first time i open the window everything works as expected, but the second time or any time after it still holds the data from the first time the window opened and it looks like the GenerateReport Method doesn't fire again.

How I can I get rid of the old data and make the GenerateReport Method gets the updated data.

This is what my ViewModel Looks like

public class ReportViewModel : ViewModelBase
{
    private string _shotListReport;
    public string ShotListReport   // the Name property
    {
        get { return _shotListReport; }
        set { _shotListReport = value; RaisePropertyChanged(""); }
    }  

    public ReportViewModel (ShotListViewModel ShotListViewModel)
    {
        ShotList = ShotListViewModel.AllShots;
        SceneList = ShotListViewModel.SceneCollectionView;

        GenerateReport();
    }

    public ListCollectionView SceneList { get; set; }
    public ObservableCollection<Shot> ShotList { get; set; }

    private void GenerateReport()
    {
        FlowDocument doc = new FlowDocument();

        //DO STUFF

        ShotListReport = new TextRange(doc.ContentStart, doc.ContentEnd).Text;
     }   
}
6
  • When dou you call to this func: ShotListReportViewModel??
    – Kram
    Jul 14, 2015 at 8:22
  • youll probably need to implement some code on the window closing event that gets rid of bindings etc and sets all the used datasources to null or empty, and repopulate all data on opening. Jul 14, 2015 at 8:25
  • @Kram. ShotListReportViewModel was a typo mistake which I updated to ReportViewModel. The function gets called when the window opens
    – Phil
    Jul 14, 2015 at 8:27
  • Look it sounds like your problem is that you send ShotListViewModel property that already registered with data. Try rebuild your ShotListViewModel before sending it to your new VM.
    – Kram
    Jul 14, 2015 at 8:30
  • Seems like you're reusing your ReportViewModel or your ShotListViewModel without properly clearing the data. As Kram and Impin say, you need to either scrap them and rebuild them every time, or implement proper cleaning logic if you really want to reuse them.
    – almulo
    Jul 14, 2015 at 9:29

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Browse other questions tagged or ask your own question.