繁体   English   中英

如何从WPF中的另一个页面获取RichTextBox文本的访问权限

[英]How to get access richtextbox text from another page in wpf

我正在尝试做某种向导。 我在框架中使用navigationservice 第二帧包括一个RichTextBox ,我需要获取其文本,但出现以下错误

public static string  attext
{
  get
  {
    string aciklama_t_text = new TextRange(aciklama_t.Document.ContentStart, aciklama_t.Document.ContentEnd).Text;
    return aciklama_t_text;
  }
}

在我的框架中aciklama_t = richtextbox

错误是:

错误CS0120非静态字段,方法或属性'wpage2.aciklama_t'需要对象引用

按钮不在框架中,如下所示:

[ 按钮不在框架中]

不必一定是这种方式。 如果还有其他解决方案,请告诉我。 我是一个非常新的C#用户。

我不太确定您要做什么。 由于aciklama_t是非静态变量,因此不应将其置于静态属性中。

像这样的东西解决了异常:

public string attext
{
    get
    {
        string aciklama_t_text = new TextRange(aciklama_t.Document.ContentStart, aciklama_t.Document.ContentEnd).Text;
        return aciklama_t_text;
    }
}

更新资料

似乎您应该在wpage2中添加一个变量,并添加下面的行,然后您可以访问PreviousPage

var wpage2 = new wpage2();
wpage2.PreviousPage = this;  //add this line
wizardframe.NavigationService.Navigate(wpage2);
introtest = "wpage2";
public wizard()
{
    InitializeComponent();
    var intro = new intro();
    wizardframe.NavigationService.Navigate(intro);
} // this is the intro page.

private void ileri_b1_Click(object sender, RoutedEventArgs e)
{
    string introtest = "intro";
    if (introtest == "intro")
    {
        var wpage2 = new wpage2();
        wizardframe.NavigationService.Navigate(wpage2);
        introtest = "wpage2";
    }
    else if (introtest == "wpage2")
    {        
        string fileName = String.Format(@"{0}\temp\aciklama.txt", Environment.CurrentDirectory);
        StreamWriter file = new StreamWriter(fileName);
        file.Write(attext);
        file.Close(); // this is the "Ileri" Button click event.Just saving file.
    }

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM