Question

I am trying to create a simple GUI application which changes the value of a string when it is changed in the GUI interface. The cs code is as follows:

    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 TryBinding
    {
    /// <summary>
    /// Interaction logic for MainWindow.xaml
    /// </summary>
    public partial class MainWindow : Window
    {
        public MainWindow()
        {
            InitializeComponent();           
        }

        consle myconsole = new consle();
    }

    public class consle
    {
        public string mainstr {get; set;}
        private int change = 23;

        public void consle()
        { 
        }

        public void wrStr()
        {
            change = 44;
        }
    }
}

and the XAML code is as follows:

<Window x:Class="TryBinding.MainWindow"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:local="clr-namespace:TryBinding"
    Title="MainWindow" Height="350" Width="525">

<Window.DataContext>
    <local:consle x:Name="Data" mainstr="maintry"/>
</Window.DataContext>            

    <Grid>

        <Button Content="Button" HorizontalAlignment="Left" Margin="244,37,0,0" VerticalAlignment="Top" Width="75"/>

    <TextBlock HorizontalAlignment="Left" Margin="131,43,0,0" TextWrapping="Wrap" VerticalAlignment="Top" Text="{Binding Path=mainstr}" />

        <CheckBox x:Name="ok" Content="CheckBox" HorizontalAlignment="Left" Margin="131,76,0,0" VerticalAlignment="Top"/>

    </Grid>    

but I am getting the error:

Error 1 The name "consle" does not exist in the namespace "clr-namespace:TryBinding".

Error 2 'consle': member names cannot be the same as their enclosing type   

I am not able to understand why its happening since the class consle exists in the namespace, and the consle() is a constructor.

Was it helpful?

Solution

your constructor shoule look like

 public consle()
    {
    }

Constructor doesn't have the datatype.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top