首页 > 解决方案 > Ironpython wpf RichTextBox

问题描述

如何在 Ironpython 中检索 RichTextBox 的内容?XAML:

<RichTextBox
            x:Name = "Sheet_Name"
            Grid.Column="0"
            Grid.Row="0"
            HorizontalAlignment="Left"
            VerticalAlignment="Top"
            Margin="174,62,0,0"
            Width="348"
            Height="476" />

这是铁蟒:

import clr
clr.AddReference('System.Windows.Forms')
clr.AddReference('IronPython.Wpf')
from pyrevit import script
xamlfile = script.get_bundle_file('ui.xaml')
import wpf
from System import*
class MyWindow(Windows.Window):
    def __init__(self):
        wpf.LoadComponent(self, xamlfile)

    def Create_Sheets(self,sender,args):
        RTB = self.Sheet_Number
        TR = TextRange(RTB.Document.ContentStart, RTB.Document.ContentEnd).Text
    def Help(self,sender,args):
        print('Help')

MyWindow().ShowDialog()

上述方法不起作用,因为未定义 TextRange。

编辑: 如果导入以下内容,则上述工作:

from System.Windows.Documents import TextRange 

标签: wpfrichtextboxironpython

解决方案


推荐阅读