Willkommen auf myCSharp.de! Anmelden | kostenlos registrieren
 | Suche | FAQ

Hauptmenü
myCSharp.de
» Startseite
» Forum
» Suche
» Regeln
» Wie poste ich richtig?

Mitglieder
» Liste / Suche
» Wer ist online?

Ressourcen
» FAQ
» Artikel
» C#-Snippets
» Jobbörse
» Microsoft Docs

Team
» Kontakt
» Cookies
» Spenden
» Datenschutz
» Impressum

  • »
  • Portal
  • |
  • Mitglieder
Beiträge von Schleenz1984
Thema: RichTextBox does not contain a definition for "Text"
Am im Forum: GUI: WPF und XAML

Hi Developers,

I am trying to write a simple program to retrieve the ouput when calling a URL and to present it when a button is clicked.

This seems to be a rather simple topic, however, I am stuck und frustrated :)

I have written this as a console application without issues but I seem to have problem with developing a WPF application.

The compiler throws the following error (I could not find any suitable solution for my code although a lot of information are available)

Fehler
Error CS1061 'RichTextBox' does not contain a definition for 'Text' and no accessible extension method 'Text' accepting a first argument of type 'RichTextBox' could be found (are you missing a using directive or an assembly reference?)
GetWebsite URL C:\Users\c5219207\source\repos\GetWebsite URL\GetWebsite URL\MainWindow.xaml.cs
38 Active

I have the following 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;
using System.Net;
using System.IO;
namespace GetWebsite_URL
{
    /// <summary>
    /// Interaction logic for MainWindow.xaml
    /// </summary>
    public partial class MainWindow : Window
    {
        public MainWindow()
        {
            InitializeComponent();
        }


        private void getMetar_Click_1(object sender, RoutedEventArgs e)
                {
                    string url = metarUrl.Text;
                    HttpWebRequest request = (HttpWebRequest)WebRequest.Create(url);
                    HttpWebResponse response = (HttpWebResponse)request.GetResponse();
                    StreamReader sr = new StreamReader(response.GetResponseStream());
                    metarOutput.Text = sr.ReadToEnd();
                    sr.Close();

                }



    }
}
###########################################

And the follwing for the xaml
<Window x:Class="GetWebsite_URL.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:GetWebsite_URL"
        mc:Ignorable="d"
        Title="MainWindow" Height="450" Width="800">
    <Grid>
        <Button x:Name="getMetar" Content="Button" HorizontalAlignment="Left" Margin="56,84,0,0" VerticalAlignment="Top" Width="94" Height="33" Click="getMetar_Click_1"/>
        <TextBox x:Name="metarUrl" HorizontalAlignment="Left" Margin="191,84,0,0" Text="TextBox" TextWrapping="Wrap" VerticalAlignment="Top" Width="237" Height="34"/>
        <RichTextBox x:Name="metarOutput" Margin="56,161,251,65"/>

    </Grid>
</Window>

Best regards