Laden...

RichTextBox does not contain a definition for "Text"

Erstellt von Schleenz1984 vor 4 Jahren Letzter Beitrag vor 4 Jahren 1.351 Views
Thema geschlossen
S
Schleenz1984 Themenstarter:in
1 Beiträge seit 2020
vor 4 Jahren
RichTextBox does not contain a definition for "Text"

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)

Fehlermeldung:
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

692 Beiträge seit 2008
vor 4 Jahren

Hello Schleenz1984,

here is an example from RichTextBox


public BasicRichTextBoxWithContentExample()
        {
            StackPanel myStackPanel = new StackPanel();

            // Create a FlowDocument to contain content for the RichTextBox.
            FlowDocument myFlowDoc = new FlowDocument();

            // Create a Run of plain text and some bold text.
            Run myRun = new Run("This is flow content and you can ");
            Bold myBold = new Bold(new Run("edit me!"));

            // Create a paragraph and add the Run and Bold to it.
            Paragraph myParagraph = new Paragraph();
            myParagraph.Inlines.Add(myRun);
            myParagraph.Inlines.Add(myBold);

            // Add the paragraph to the FlowDocument.
            myFlowDoc.Blocks.Add(myParagraph);

            RichTextBox myRichTextBox = new RichTextBox();

            // Add initial content to the RichTextBox.
            myRichTextBox.Document = myFlowDoc;
            
            myStackPanel.Children.Add(myRichTextBox);
            this.Content = myStackPanel;
        }

Best regards,
Quaneu

4.931 Beiträge seit 2008
vor 4 Jahren

Für eine read-only Anzeige von Text benutze besser einen TextBlock, welches auch eine Text-Property hat.

16.807 Beiträge seit 2008
vor 4 Jahren

Frecher Copy-Paste-Crosspost, daher zu.
How to retrieve simple output from a URL?

Forenregeln beachten!
[Hinweis] Wie poste ich richtig?
So läuft das hier nicht 😉

Thema geschlossen