Click here to Skip to main content
15,877,857 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
hello coders, I have tried to run this code but the error "Method name expected" popped up and I have no idea what is wrong

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.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Shapes;

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

        private void Colour1_click(object sender, RoutedEventArgs e)
        {
            var Scheme1 = "#FF9900";
            var Scheme2 = "#3DD3E9";
            Change_colour(Scheme1, Scheme2);
        }

        public void Change_colour(string Scheme1, string Scheme2)
        {
            var converter = new BrushConverter();
            var brush1 = (Brush)converter.ConvertFromString(Scheme1);
            var brush2 = (Brush)converter.ConvertFromString(Scheme2);
            Rectangle1.Fill = brush1;
            header_block.Fill = brush2;
        }

        private void Background1_clicked(object sender, RoutedEventArgs e)
        {
            string Background = "images/background.png";
            Change_background(Background);
        }

        public void Change_background(string Background)
        {
            var converter1 = new BrushConverter();
            var Background_set = (ImageBrush)converter1.ConvertFromString(Background);
            ImageBrush ImageSource = Background_set;
        }
    }
}
Posted
Updated 3-Aug-19 0:18am
v3
Comments
OriginalGriff 3-Aug-19 4:23am    
Where did it occur?
At a guess, it's caused by the code immediately above that - since there doesn't appear to be any error in that code.
QuantumNova 3-Aug-19 5:04am    
I have edited it so it contains all code and the console says the error occurs at line 33 which it the empty line between Colour1_click and Change_colour
Patrice T 3-Aug-19 4:30am    
The message includes the position of error !
QuantumNova 3-Aug-19 5:05am    
the error occurs at line 33 which it the empty line between Colour1_click and Change_colour
Patrice T 3-Aug-19 6:28am    
Use Improve question to update your question.
So that everyone can pay attention to this information.

1 solution

You need to start working more with Visual Studio: teh error is not in that code. If I create a new WPF app project and paste that code into the MainWindows.xaml.cs file, the only errors I get refer to controls I don't have:
Rectangle1.Fill = brush1;
header_block.Fill = brush2;
There is no mention of a "method name expected" error at all, and providing controls with matching names won't cause it either.

So start by double clicking the error message in the Errors pane, and VS will take you directly to the line. Look closely at it, and the parts with the red underline, and also examine the code immediately above it. It may be you have forgotten a semicolon, or close bracket of some kind - we can't tell.

But it isn't in that code.
 
Share this answer
 
Comments
QuantumNova 3-Aug-19 7:57am    
Thanks for trying to help and giving this helpful advice, really appreciated it man :)
OriginalGriff 3-Aug-19 8:04am    
You're welcome!

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