[英]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.