9 Replies - 2448 Views - Last Post: 26 November 2012 - 06:30 AM

#1 Saturisk  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 5
  • Joined: 15-November 12

Slideshow to use in XNA

Posted 21 November 2012 - 06:07 PM

Trying to make a slideshow out of C# to use in a program I am making in XNA.
using System;
using System.Windows;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Xml.Linq;
using System.Windows.Media.Imaging;
using System.Windows.Media.Animation;

namespace test2
{
    partial class Windowdundundun : MainWindow
    {

        int count;
        private List<ImageEntities> Images = ImageViews.GetAllImageData();

        class ImageEntities
        {
            public String ImagePath
            {
                get;
                set;
            }
            
        }

        public static class ImageViews
        {
            public static List<ImageEntities> GetAllImageData()
            {
                

                try
                {
                    //Load XML File  
                    XDocument XDoc = Xdocument.Load("Images.xml");
                    // Query for retriving all Image data from XML  
                    var Query = from Q in XDoc.Descendants("Image")
                                select new ImageEntities
                                {
                                    ImagePath = Q.Element("ImagePath").Value
                                };
                    // Return Image Data  
                    return Query.ToList<ImageEntities>();
                }
                catch (Exception ex)
                {
                    throw new Exception(ex.Message);
                }
            }
        }
        public void btnNext_Click(object sender, RoutedEventArgs e)
        {
            if (count < Images.Count - 1)
            {
                count++;
                PlaySlideShow(count);
            }
            else
            {
                count = 0;
                PlaySlideShow(count);
            }
        }
        public void btnPrev_Click(object sender, RoutedEventArgs e)
        {
            if (count > 0)
            {
                count--;
                PlaySlideShow(count);
            }
            else
            {
                count = Images.Count - 1;
                PlaySlideShow(count);
            }
        }

        public void PlaySlideShow(int cnt)
        {
            

            BitmapImage image = new BitmapImage();
            image.BeginInit();
            image.UriSource = new Uri(Images[cnt].ImagePath, UriKind.Relative);
            image.EndInit();
            myImage.Source = image;


        }

    }
}


I don't know if I am even doing it right first of all, but that's besides the point. I get an error in
public static List<ImageEntities> GetAllImageData()
That says "Inconsistent Accessability" error I don't understand why it gives me that error as I understand that it is just trying to get something that it is unable to, but everything is public.

Any knowledge on the subject and if I'm even doing it right would be greatly appreciated.

Is This A Good Question/Topic? 0
  • +

Replies To: Slideshow to use in XNA

#2 tlhIn`toq  Icon User is offline

  • Please show what you have already tried when asking a question.
  • member icon

Reputation: 5431
  • View blog
  • Posts: 11,641
  • Joined: 02-June 10

Re: Slideshow to use in XNA

Posted 21 November 2012 - 09:46 PM

Is .GetAllImageDate() method within ImageViews marked public?

UPDATE: OH, there it is. Yes its public. Well, it was a thought.

This post has been edited by tlhIn`toq: 21 November 2012 - 09:48 PM

Was This Post Helpful? 0
  • +
  • -

#3 tlhIn`toq  Icon User is offline

  • Please show what you have already tried when asking a question.
  • member icon

Reputation: 5431
  • View blog
  • Posts: 11,641
  • Joined: 02-June 10

Re: Slideshow to use in XNA

Posted 21 November 2012 - 09:51 PM

Oh... line 18 - class ImageEntities is NOT public, therefore the other class of ImageViews isn't entitled to see it or make use of it.
Was This Post Helpful? 1
  • +
  • -

#4 Saturisk  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 5
  • Joined: 15-November 12

Re: Slideshow to use in XNA

Posted 22 November 2012 - 07:44 PM

Back again! Yay. Wait no.

Anyways, I got farther on my code to make a slideshow in c# using XML and XAML, two things I am really unsure about, but I am also using a WPF application, something I know nothing about, I am just guessing my way through.

using System;
using System.Collections.Generic;
using System.Linq;
using System.Xml.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;

namespace test2
{
    /// <summary>
    /// Interaction logic for Mainwindow.xaml
    /// </summary>
    public partial class MainWindow : Window
    {
        public MainWindow()
        {
            InitializeComponent();
        }

        int count;

        private List<ImageEntities> Images = ImageViews.GetAllImageData();

        public class ImageEntities
        {
            public String ImagePath
            {
                get;
                set;
            }

        }

        public static class ImageViews
        {
            public static List<ImageEntities> GetAllImageData()
            {


                try
                {
                    //Load XML File  
                    XDocument XDoc = Xdocument.Load("Images.xml");
                    // Query for retriving all Image data from XML  
                    var Query = from Q in XDoc.Descendants("Image")
                                select new ImageEntities
                                {
                                    ImagePath = Q.Element("ImagePath").Value
                                };
                    // Return Image Data  
                    return Query.ToList<ImageEntities>();
                }
                catch (Exception ex)
                {
                    throw new Exception(ex.Message);
                }
            }
        }
        public void btnNext_Click(object sender, RoutedEventArgs e)
        {
            if (count < Images.Count - 1)
            {
                count++;
                PlaySlideShow(count);
            }
            else
            {
                count = 0;
                PlaySlideShow(count);
            }
        }
        public void btnPrev_Click(object sender, RoutedEventArgs e)
        {
            if (count > 0)
            {
                count--;
                PlaySlideShow(count);
            }
            else
            {
                count = Images.Count - 1;
                PlaySlideShow(count);
            }
        }

        public void PlaySlideShow(int cnt)
        {


            BitmapImage image = new BitmapImage();
            image.BeginInit();
            image.UriSource = new Uri(Images[cnt].ImagePath, UriKind.Relative);
            image.EndInit();
            myImage.Source = image;


        }

    }
}


This is the code in my WindowMain.xaml.cs file, the file that's autocreated for Windowmain.xaml, my first question is, can I have my code in there or do I have to make a new class file?

<Window x:Class="test2.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">
    <Grid>
        <Image x:Name="myImage" HorizontalAlignment="Left" VerticalAlignment="Top" Stretch="Fill"/>
        <Button x:Name="btnNext" Content="&gt;" HorizontalAlignment="right" Height="20" Margin="0,0,10,0" VerticalAlignment="Center" Width="21" RenderTransformOrigin="1.524,0.421" Click="btnNext_Click"/>
        <Button x:Name="btnPrev" Content="&lt;" HorizontalAlignment="Left" Height="20" Margin="10,0,0,0" VerticalAlignment="center" Width="21" RenderTransformOrigin="1.524,0.421" Click="btnPrev_Click"/>
    </Grid>
</Window>



This is the code for my WindowMain.xaml file.

Everything I thought was self explanatory until I recieved an error "'The invocation of the constructor on type 'test2.MainWindow' that matches the specified binding constraints threw an exception.' Line number '3' and line position '9'." I don't understand what it means at what line number it's talking about...

Any help would be appreciated! Sorry again~
Was This Post Helpful? 0
  • +
  • -

#5 tlhIn`toq  Icon User is offline

  • Please show what you have already tried when asking a question.
  • member icon

Reputation: 5431
  • View blog
  • Posts: 11,641
  • Joined: 02-June 10

Re: Slideshow to use in XNA

Posted 22 November 2012 - 10:05 PM

You already have a thread open for this:
http://www.dreaminco...1&#entry1751811

Please don't keep opening threads for the same thing each time you have an update.
Was This Post Helpful? 0
  • +
  • -

#6 Saturisk  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 5
  • Joined: 15-November 12

Re: Slideshow to use in XNA

Posted 23 November 2012 - 01:29 PM

View PosttlhIn`toq, on 22 November 2012 - 10:05 PM, said:

You already have a thread open for this:
http://www.dreaminco...1&#entry1751811

Please don't keep opening threads for the same thing each time you have an update.



I apologize I guess I didn't read the "how-to" on posting threads.
Was This Post Helpful? 0
  • +
  • -

#7 bonyjoe  Icon User is offline

  • D.I.C Addict
  • member icon

Reputation: 175
  • View blog
  • Posts: 548
  • Joined: 08-September 10

Re: Slideshow to use in XNA

Posted 25 November 2012 - 11:22 AM

Well it could be because you seem to have created a new class inside your window partial class, move that out to a separate class file instead.

Also with the way the .xaml.cs files work, you should initialise things in the constructor rather than at declaration so this line:

private List<ImageEntities> Images = ImageViews.GetAllImageData();


should probably be split up so that

Images = ImageViews.GetAllImageData();


Is in the constructor.

Though I'm a bit rusty on WPF so I may just be remembering incorrectly.

When does the error occur? At compile time or when you open the window?

edit: also you are declaring a static class inside a non static class, I'm not sure how the constructor deals with that, but I can imagine it shouldn't work

This post has been edited by bonyjoe: 25 November 2012 - 11:24 AM

Was This Post Helpful? 0
  • +
  • -

#8 tlhIn`toq  Icon User is offline

  • Please show what you have already tried when asking a question.
  • member icon

Reputation: 5431
  • View blog
  • Posts: 11,641
  • Joined: 02-June 10

Re: Slideshow to use in XNA

Posted 25 November 2012 - 11:47 AM

View Postbonyjoe, on 25 November 2012 - 12:22 PM, said:

Well it could be because you seem to have created a new class inside your window partial class, move that out to a separate class file instead.

There is nothing wrong with that if that is the intention. I do it all the time. It makes a proper hierarchy of things. For example:

class Dog
{
   List<trick> Tricks = new List<trick>();
   class Trick
   {
   }
}

This is a perfectly reasonable thing to do because the Trick class doesn't have a big purpose at the root level of the application. But when you are dealing with a dog then you would want to see it

Dog Fido = new Dog();
Fido.Tricks.Add(new Dog.Trick();


View Postbonyjoe, on 25 November 2012 - 12:22 PM, said:

Also with the way the .xaml.cs files work, you should initialise things in the constructor rather than at declaration so this line:

Not sure where you are getting 'should' from. You 'can'. But personally I like to assign a value to all variables at the time of creation so there is never a chance of them remaining null.


View Postbonyjoe, on 25 November 2012 - 12:22 PM, said:

edit: also you are declaring a static class inside a non static class, I'm not sure how the constructor deals with that, but I can imagine it shouldn't work

Perfectly legal. It just means that all the unique instances of the parent class will share a single instance of the static child class. Let's say you have a bunch of... SodaCans. Each SodaCan is its own instance because they can be consumed individually. But since they all have the same LabelGraphic why waste the memory storing 1,000 copies of the same graphic? If they all share the same static LableGraphic they would all update when you had to make a change, such as a new UPC code or a new image for the Christmas holidays.

A more computer related example might be that several classes all share a single static instance of a serial COM port (Which can't be opened multiple times by multiple instances of a class). All the classes do something different when a message comes in on the COM port. But they are all looking at the same static SerialPort.

This post has been edited by tlhIn`toq: 25 November 2012 - 11:48 AM

Was This Post Helpful? 1
  • +
  • -

#9 Saturisk  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 5
  • Joined: 15-November 12

Re: Slideshow to use in XNA

Posted 25 November 2012 - 09:33 PM

I've done different things, created new classes for the classes I created, but i either get that first error or it says I never created a class for the buttons on the slideshow

Error	2	'test2.MainWindow' does not contain a definition for 'btnPrev_Click' and no extension method 'btnPrev_Click' accepting a first argument of type 'test2.MainWindow' could be found (are you missing a using directive or an assembly reference?)	myfileaddress\Mainwindow.xaml	8	78	test2



Tells me that in my Xaml code for MainWindow that I never once told it that I created a class for each of the buttons and what they do
Was This Post Helpful? 0
  • +
  • -

#10 bonyjoe  Icon User is offline

  • D.I.C Addict
  • member icon

Reputation: 175
  • View blog
  • Posts: 548
  • Joined: 08-September 10

Re: Slideshow to use in XNA

Posted 26 November 2012 - 06:30 AM

View PosttlhIn`toq, on 25 November 2012 - 07:47 PM, said:

...


Ah ok, thanks, that makes sense.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1