silverlight - 如何在 Silverlight 4 中使用 RichTextBox 进行选择对齐?

标签 silverlight properties silverlight-4.0 richtextbox selection

我似乎无法弄清楚如何在新的 RichTextBox 中进行选择对齐,我有一个想法,我需要将选择转换为支持对齐的段落类型,但似乎无法弄清楚这一点。 Silverlight 示例中没有一个具有此功能,但我确信这是可能的。
我有这段代码,但不起作用 - 因为我认为我需要选择一个段落,因为它总是返回并且异常“值不在预期范围内”。

Editor.Selection.SetPropertyValue(Paragraph.TextAlignmentProperty, TextAlignment.Left)

我确保首先检查有效选择,如下代码适用于“粗体”:

If Editor.Selection.Text.Length > 0 Then ' Text Selected
    If TypeOf Editor.Selection.GetPropertyValue(Run.FontWeightProperty) Is FontWeight _
        AndAlso DirectCast(Editor.Selection.GetPropertyValue(Run.FontWeightProperty), FontWeight) = FontWeights.Normal Then
        Editor.Selection.SetPropertyValue(Run.FontWeightProperty, FontWeights.Bold)
    Else
        Editor.Selection.SetPropertyValue(Run.FontWeightProperty, FontWeights.Normal)
    End If
End If
Editor.Focus()

XAML 示例:

<Paragraph TextAlignment="Right">Example</Paragraph>

上面的内容适用于 RichTextBox 的内容,但是我需要根据选择以编程方式执行此操作 - 就像在写字板中一样。

最佳答案

使用silverlight 4发布版本,这就是我所做的。 Editor.Selection.ApplyPropertyValue(Paragraph.TextAlignmentProperty, TextAlignment.Left)

假设当前选择了您要证明的文本。

关于silverlight - 如何在 Silverlight 4 中使用 RichTextBox 进行选择对齐?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1979758/

相关文章:

java - 跨平台可执行/运行时交付方法

c# - 如何阻止 ReSharper 在需要 Action 的 lambda 表达式上显示错误?

c# - 使属性(property)成为强制性的

java - 在 Spring 中配置系统属性

silverlight - Silverlight 4 浏览器外应用程序可以运行其他应用程序吗?

c# - 如何让Silverlight UserControl填充网页?

silverlight-4.0 - MVVM/用户控件和 View = ViewModel 约定

.net - XAML 性能 : Set alpha channel of a brush vs. FrameworkElement 的不透明度

具有大型结果集的 WCF 方法 - 可视化跟踪传输进度

c++ 获取 Boost::Graph 的顶点属性