question

davidg-9488 avatar image
0 Votes"
davidg-9488 asked LeonardoArrighi-5150 commented

WPF MVVM viewmodel App.xaml OnStartup calling more than one call

Hey all I am terrible at MVVM so I hope someone more knowledgeable will be able to answer my question.

I have a app that, when started, first calls the view model (App.xaml) and calls a function that passes images from a folder(s). The issue being that I am unsure how to call more than just that one call:

 protected override void OnStartup(StartupEventArgs e)
 {
     base.OnStartup(e);
    
     string boxPath = Environment.CurrentDirectory + @"\boxes";
     // set the update interval
     var imageSource = new ImageSource(Path.Combine(boxPath, "box1"), TimeSpan.FromHours(1));
     var viewModel = new MainWindowViewModel(imageSource);
     var window = new MainWindow()
     {
         DataContext = viewModel
     };
    
     window.Closed += (s, a) => { viewModel.Dispose(); };
     window.Show();
 }

The code ImageSource(Path.Combine(boxPath, "box1"), TimeSpan.FromHours(1)); is what I am in need of modifying so that I can include calls for all my boxes (1-10) instead of just that one.

How would I modify this in order to call more than one box1? I'd really rather call the boxes from a viewmodel instead of inside the app.xaml but I am not sure if that's possible or not?

dotnet-csharpwindows-wpfdotnet-wpf-xaml
· 1
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

Wasn't my answer in your previous post not considerable? If not, could you please argue the reason?

0 Votes 0 ·

0 Answers