Toolbox button not creating Event Handler

  • Thread starter Thread starter Ann Maybury
  • Start date Start date
A

Ann Maybury

Guest
I crated a project many ways and still get an error when I try to add a button. My latest try was using


When I used the toolbar to add a button and then added the click as shown in the mainWindow.xaml file, the event handler did not appear in the main window.xaml.cs file. What frameworks should I select to poduce a desktop application using C#? This project has just been started and the only addition is the button that is not working. I am using Visual Studio 16.5 but had this same problem with 16.4.x.

Copies of the error message, the xsml code and the xaml.cs code are shown below.

Thanks in advance for any help. ann.maybury@gmail.com


ERROR MESSAGE:

Severity Code Description Project File Line Suppression State
Error CS1061 'MainWindow' does not contain a definition for 'Button_Click' and no accessible extension method 'Button_Click' accepting a first argument of type 'MainWindow' could be found (are you missing a using directive or an assembly reference?) Ann_WpfApp1 D:\__Visual Studio\C#-DeskTop\Ann_WpfApp1\Ann_WpfApp1\MainWindow.xaml 10 Active


XAML CODE

<Window x:Class="Ann_WpfApp1.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:local="clr-namespace:Ann_WpfApp1"
mc:Ignorable="d"
Title="MainWindow" Height="450" Width="800">
<Grid>
<Button Content="Button" Click ="Button_Click" HorizontalAlignment="Left" Margin="125,10,0,0" VerticalAlignment="Top" Width="75"/>

</Grid>
</Window>

XAML.CS CODE

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.Navigation;
using System.Windows.Shapes;

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

Continue reading...
 
Back
Top