Click here to Skip to main content
15,879,239 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Non-invocable member cannot be used like a method
error for uri
The name ImageSource does not exist in the current context
card does not contain a definition for cards and total.
How to define cards andtotal values in class?

Can anyone please help me with these Errors?

What I have tried:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Threading;
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;
using System.Windows.Controls.Primitives;
using System.Data;
using System.ComponentModel;
using static System.Net.Mime.MediaTypeNames;
using System.IO;

namespace solitair
{
    /// <summary>
    /// Interaction logic for MainWindow.xaml
    /// </summary>
    public partial class MainWindow : Window
    {
        BackgroundWorker backgroundWorker1 = new BackgroundWorker();
        public MainWindow()
        {
            InitializeComponent();
            pbStatus.Visibility = Visibility.Hidden;
            Reset();

        }
        public void Reset()

        {

            Uri("image\\Cards\\back.png");

            ImgCard.Source = imageSource;

            OfCardstext.Content = "";

            Cardtext.Content = "";

            Totaltext.Content = "";

            ListHeader.Items.Clear();

        }

        private void TextBox_TextChanged(object sender, TextChangedEventArgs e)
        {

        }

        private void hscroll_ValueChanged(object sender, RoutedPropertyChangedEventArgs<double> e)
        {
        }
        private void Button_Click(object sender, RoutedEventArgs e)
        {
            Shuffle.Visibility = Visibility.Visible;

            pbStatus.Visibility = Visibility.Visible;
        }
        private void Button_Click_1(object sender, RoutedEventArgs e)
        {
            backgroundWorker1 = new BackgroundWorker();

            backgroundWorker1.DoWork += backgroundWorker1_DoWork;

            backgroundWorker1.ProgressChanged +=

            backgroundWorker1_ProgressChanged;

            backgroundWorker1.RunWorkerCompleted +=

            backgroundWorker1_RunWorkerCompleted;

            backgroundWorker1.WorkerReportsProgress = true;

            backgroundWorker1.WorkerSupportsCancellation = true;

            backgroundWorker1.RunWorkerAsync(100);
        }
        private void backgroundWorker1_DoWork(object sender, DoWorkEventArgs e)

        {

            int result = 0;

            for (int i = 1; i <= 100; i++)

            {

                if (backgroundWorker1.CancellationPending)

                {

                    e.Cancel = true;

                    break;

                }

                Thread.Sleep(100);

                // Report progress.

                backgroundWorker1.ReportProgress(i);

                //TODO: your result code here

            }

            e.Result = result;

        }

        private void backgroundWorker1_ProgressChanged(object sender, ProgressChangedEventArgs e)

        {

            int item = e.ProgressPercentage;

            // Change the value of the ProgressBar to the BackgroundWorker progress.

            pbStatus.Value = item;

            // Set the text.

        }

        void backgroundWorker1_RunWorkerCompleted(object sender, RunWorkerCompletedEventArgs e)

        {

            if (e.Cancelled)

            {

            }

            else

            {

                Random RMNumber = new Random();

                int Card = RMNumber.Next(1, 12);

                var CardCodes = new List<string> { " c", " d ", "s", " h" };

                Random RMChar = new Random();

                int index = RMChar.Next(CardCodes.Count);

                var Codes = CardCodes[index];

                String CardName = "image\\Cards\\" + Codes;


                if (Card > 10)

                {

                    CardName = CardName + Convert.ToString(Card) + ".png";

                }

                else

                {

                    CardName = CardName + "0" + Convert.ToString(Card) + ".png";

                }

                ImageSource imageSource = new BitmapImage(new Uri(CardName));

                ImgCard.Source = imageSource;

                string CardNm = "";

                if (Codes == "c")

                {

                    if (Card == 11)

                    {

                        CardNm = "Jack of Clubs";

                    }

                    else if (Card == 12)

                    {

                        CardNm = "Queen of Clubs";

                    }

                    else if (Card == 13)

                    {

                        CardNm = "King of Clubs";

                    }

                    else

                    {

                        CardNm = Convert.ToString(Card) + "of Clubs";

                    }

                }

                else if (Codes == "d")

                {

                    if (Card == 11)

                    {

                        CardNm = "Jack of Diamonds";

                    }

                    else if (Card == 12)

                    {

                        CardNm = "Queen of Diamonds";

                    }

                    else if (Card == 13)

                    {

                        CardNm = "King of Diamonds";

                    }

                    else

                    {

                        CardNm = Convert.ToString(Card) + "of Diamonds";

                    }

                }

                else if (Codes == "s")

                {

                    if (Card == 11)

                    {

                        CardNm = "Jack of Spades";

                    }

                    else if (Card == 12)

                    {

                        CardNm = "Queen of Spades";

                    }

                    else if (Card == 13)

                    {

                        CardNm = "King of Spades";

                    }

                    else

                    {

                        CardNm = Convert.ToString(Card) + "of Spades";

                    }

                }

                else if (Codes == "h")

                {

                    if (Card == 11)

                    {

                        CardNm = "Jack of Hearts ";

                    }

                    else if (Card == 12)

                    {

                        CardNm = "Queen of Hearts";

                    }

                    else if (Card == 13)

                    {

                        CardNm = "King of Hearts";

                    }

                    else

                    {

                        CardNm = Convert.ToString(Card) + "of Hearts";

                    }

                }

                int total = 0;

                if (ListHeader.Items.Count> 0)

                {
                    total = Card + Convert.ToInt32(Totaltext.Content);

                    OfCardstext.Content = Convert.ToInt32(OfCardstext.Content) + 1;

                    Totaltext.Content = total;
                }



                else

                {

                    total = Card;

                    OfCardstext.Content = 1;

                    Cardtext.Content = Card;

                    Totaltext.Content = total;

                }

                Cardtext.Content = Card.ToString();

                ListHeader.Items.Add(new card { Cards = CardNm, Total = total });


            }

        }

    }
}
Posted
Updated 5-May-17 21:37pm
v2
Comments
OriginalGriff 6-May-17 1:48am    
Not from that, we can't.
We need context in order to look at those random line - and we don't have any.
Edit your question, and paste in the method that generates the error, then copy and paste the error message and tell us which line the compiler finds it on.
Use the "Improve question" widget to edit your question and provide better information.

1 solution

By the bit of code, we can not identify exact issue but your error says your resolution steps clearly

1) The name ImageSource does not exist in the current context

ImageSource is not declared in the current scope, You need to declare at where you are
using same or make sure it should be accessible where it needed.

2) card does not contain a definition for cards and total.

There is no defination for cards and total in card

3) Non-invocable member cannot be used like a method
Comment Uri from reset
public void Reset()

{

// Uri("image\\Cards\\back.png");

ImgCard.Source = imageSource;

OfCardstext.Content = "";

Cardtext.Content = "";

Totaltext.Content = "";

ListHeader.Items.Clear();

}

and set just update your bitmapimage code like this
BitmapImage myBitmapImage = new BitmapImage();

myBitmapImage.BeginInit();
myBitmapImage.UriSource = new Uri(@"your image path");


ImageSource imageSource = myBitmapImage
 
Share this answer
 
v4
Comments
Member 13170154 6-May-17 2:16am    
May i know how to declare Them?
uri cannot be used like a method error
imagesource is not available in the current context
Nirav Prabtani 6-May-17 2:28am    
in that code

public void Reset()

{

Uri("image\\Cards\\back.png");

ImgCard.Source = imageSource;

OfCardstext.Content = "";

Cardtext.Content = "";

Totaltext.Content = "";

ListHeader.Items.Clear();

}

where you have declared imageSource ??

Member 13170154 6-May-17 2:32am    
private ImageSource imageSource; in mainwindow.xaml
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Media.Imaging;

namespace solitair
{
class card
{
public string Cards { get; internal set; }
public int Total { get; internal set; }
}
}

i tried this. and errors for image source,card and total is gone but still uri is not solved
it will be really helpful if u can tell me where to declare them and what is the code for it.
Nirav Prabtani 6-May-17 2:34am    
Why you have set it to private ??

Make it public or declare it to a desired scope so it can be accessible
Member 13170154 6-May-17 2:39am    
So what do u suggest me? change it to public? I did. What next?
it will be really helpful if u can tell me where to declare them and what is the code for it.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900