Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. WPF
  4. WPF c# onStartUp() view model problem with multiple data inputs

WPF c# onStartUp() view model problem with multiple data inputs

Scheduled Pinned Locked Moved WPF
csharpwpfhelptutorialannouncement
3 Posts 3 Posters 9 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • S Offline
    S Offline
    StealthRT
    wrote on last edited by
    #1

    Hey all I have the following OnStartup for my WPF desktop app that goes to a local directory and gathers all the images within that folder (box1 being the example code below):

    public partial class App : Application
    {
    protected override void OnStartup(StartupEventArgs e)
    {
    base.OnStartup(e);

            // set the update interval
            var imageSource = new ImageSource(Path.Combine(@"C:\\photos\\boxes\\", "box1"), TimeSpan.FromHours(1));
            var viewModel = new MainWindowViewModel(imageSource);
    
            var window = new MainWindow()
            {
                DataContext = viewModel
            };
    
            window.Closed += (s, a) => { viewModel.Dispose(); };
            window.Show();
        }
    }
    

    This works just fine for the component I have on the MainWindow.xaml that's label box1 but the other boxes 2-9 do not load their own images from their respective folders - they all show the same images as box1 has.

    The structure of the directory is this:

     C:\\
      |-photos\\
         |boxes\\
           |box1
           |box2
           |box3
           |box4
           |box5
           |box6
           |box7
           |box8
           |box9
           |box10
    

    On the MainWindow I have this code that allows all those photos from each directory into its own element:

    L K 2 Replies Last reply
    0
    • S StealthRT

      Hey all I have the following OnStartup for my WPF desktop app that goes to a local directory and gathers all the images within that folder (box1 being the example code below):

      public partial class App : Application
      {
      protected override void OnStartup(StartupEventArgs e)
      {
      base.OnStartup(e);

              // set the update interval
              var imageSource = new ImageSource(Path.Combine(@"C:\\photos\\boxes\\", "box1"), TimeSpan.FromHours(1));
              var viewModel = new MainWindowViewModel(imageSource);
      
              var window = new MainWindow()
              {
                  DataContext = viewModel
              };
      
              window.Closed += (s, a) => { viewModel.Dispose(); };
              window.Show();
          }
      }
      

      This works just fine for the component I have on the MainWindow.xaml that's label box1 but the other boxes 2-9 do not load their own images from their respective folders - they all show the same images as box1 has.

      The structure of the directory is this:

       C:\\
        |-photos\\
           |boxes\\
             |box1
             |box2
             |box3
             |box4
             |box5
             |box6
             |box7
             |box8
             |box9
             |box10
      

      On the MainWindow I have this code that allows all those photos from each directory into its own element:

      L Offline
      L Offline
      Lost User
      wrote on last edited by
      #2

      You don't appear to be varying your input path. You need a list or a "box path counter".

      var imageSource = new ImageSource(Path.Combine(@"C:\photos\boxes\", "box1"),
      TimeSpan.FromHours(1));

      "Before entering on an understanding, I have meditated for a long time, and have foreseen what might happen. It is not genius which reveals to me suddenly, secretly, what I have to say or to do in a circumstance unexpected by other people; it is reflection, it is meditation." - Napoleon I

      1 Reply Last reply
      0
      • S StealthRT

        Hey all I have the following OnStartup for my WPF desktop app that goes to a local directory and gathers all the images within that folder (box1 being the example code below):

        public partial class App : Application
        {
        protected override void OnStartup(StartupEventArgs e)
        {
        base.OnStartup(e);

                // set the update interval
                var imageSource = new ImageSource(Path.Combine(@"C:\\photos\\boxes\\", "box1"), TimeSpan.FromHours(1));
                var viewModel = new MainWindowViewModel(imageSource);
        
                var window = new MainWindow()
                {
                    DataContext = viewModel
                };
        
                window.Closed += (s, a) => { viewModel.Dispose(); };
                window.Show();
            }
        }
        

        This works just fine for the component I have on the MainWindow.xaml that's label box1 but the other boxes 2-9 do not load their own images from their respective folders - they all show the same images as box1 has.

        The structure of the directory is this:

         C:\\
          |-photos\\
             |boxes\\
               |box1
               |box2
               |box3
               |box4
               |box5
               |box6
               |box7
               |box8
               |box9
               |box10
        

        On the MainWindow I have this code that allows all those photos from each directory into its own element:

        K Offline
        K Offline
        Kevin Marois
        wrote on last edited by
        #3

        No related to your question but.... you XAML format is absurd. That's not at all standard and will cause TAB issues.

        If it's not broken, fix it until it is. Everything makes sense in someone's mind. Ya can't fix stupid.

        1 Reply Last reply
        0
        Reply
        • Reply as topic
        Log in to reply
        • Oldest to Newest
        • Newest to Oldest
        • Most Votes


        • Login

        • Don't have an account? Register

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • World
        • Users
        • Groups