我正在尝试将RTF格式(RTF)文件加载到WPF RichTextBox中。当我执行加载时,看起来好像文件已加载到RichTextBox中,但滚动条显示时没有可见的滑块框来滚动下载。滚动条不显示底部箭头,因此滚动条的底部显示在RichTextBox的显示区域下方。这可以防止用户向下滚动。我相信我要么缺少RichTextBox的XAML属性,要么就像我加载RTF文件的方式不对。请帮忙。提前致谢。
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="*"/>
<ColumnDefinition Width="*"/>
<ColumnDefinition Width="*"/>
</Grid.ColumnDefinitions>
<Grid.RowDefinitions>
<RowDefinition Height="*"/>
<RowDefinition Height="*"/>
<RowDefinition Height="*"/>
<RowDefinition Height="*"/>
<RowDefinition Height="*"/>
<RowDefinition Height="*"/>
<RowDefinition Height="*"/>
</Grid.RowDefinitions>
<StackPanel Grid.Row="0" Grid.RowSpan="5"
Grid.Column="0" Grid.ColumnSpan="3"
VerticalAlignment="Stretch" HorizontalAlignment="Stretch">
<RichTextBox x:Name="LicenseRichTextBox" Margin="10"
VerticalAlignment="Stretch" HorizontalAlignment="Stretch"
IsReadOnly="True" VerticalScrollBarVisibility="Visible">
</RichTextBox>
</StackPanel>
<StackPanel Grid.Row="6" Grid.Column="1" Grid.ColumnSpan="3" Margin="65,20,0,0" >
<Button x:Name="CloseButton" HorizontalAlignment="Left"
Width="90" Margin="-10,0,0,0"
Click="CloseButton_Click">
<StackPanel Orientation="Horizontal">
<Image Source="{StaticResource CloseButtonImageKey}"
Margin="5,0,0,0" Height="20" Width="20" />
<TextBlock Padding="5,0,0,0" VerticalAlignment="Center"><Run Text="Close"/></TextBlock>
</StackPanel>
</Button>
</StackPanel>
</Grid>
public void LoadRTF()
{
const string EULA_Dir = @"Resources\EULA\EUlA.RTF";
string currentDir = AppDomain.CurrentDomain.BaseDirectory;
string PathToEULA = currentDir + EULA_Dir;
if (File.Exists(PathToEULA))
{
LicenseRichTextBox.Selection.Load(new FileStream(PathToEULA, FileMode.Open), DataFormats.Rtf);
}
else
{
MessageBox.Show("Unable to locate the following file " + PathToEULA);
}
}
狂野的猜测 - 你的RichTextBox
在StackPanel
内。堆叠面板不会限制他们的孩子,相反,他们有无限的内部空间,并根据他们的孩子内容增长。因此,您的文本框不受约束,因此它不认为它需要显示滚动条。
目前不在开发环境的前面所以我无法证实这一点,但尝试将其从StackPanel
中取出并看看它的作用。