WPF FlowDocument ::如何为子段落,运行等定义自定义模板 [英] WPF FlowDocument :: How Can I Define Custom Templates for the Child Paragraph, Run, etc

查看:102
本文介绍了WPF FlowDocument ::如何为子段落,运行等定义自定义模板的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我对WPF还是很陌生,所以请多多包涵。

I'm fairly new to WPF, so please bear with me.

我正在尝试自定义 RichTextBox (RTB)中的> FlowDocument 。 WPF控件是无用的,因此据我了解,我应该能够在 Document 中为每个孩子定义外观。

I am trying to customize the presentation of the various elements of a FlowDocument in a RichTextBox (RTB). WPF controls are lookless, so as I understand it I should be able to define the look for every child in the Document.

我将在实时出价工具中为此定义模板吗?每个项目的单独模板(段落部分运行等)作为资源? 为争辩起见,我想在每个 Section 周围加一个红色边框,在每个 Paragraph ,带有 Margin = 5 ,并且每个 Run 都位于Consolas中。(请参阅编辑一)

Would I define the template for this in the RTB? Separate templates for each item (Paragraph, Section, Run, etc) as resources? Let's say, for sake of argument, that I want a red border around every Section, the word "Paragraph:" before every Paragraph with a Margin="5", and every Run to be in Consolas. (see edit one)

编辑一个

我了解更多从这里提出错误问题,而不是提出正确的问题。似乎我从来没有问过我第一次真正要做什么。谁知道,也许我会学习。

I learn more here from asking the wrong question than the right one. It seems I never ask what I'm really trying to do the first time out the gate. Who knows, maybe I'll learn.

我正在尝试定义 DataTemplate ItemTemplate (我认为)类似于 ListBox 。最终目标是在RTB中使用源视图 HTML编辑器。我希望一个段落XAML元素在RTB中呈现为:

I am trying to define a DataTemplate or an ItemTemplate (I think) similar to a ListBox. The ultimate goal is a "source view" HTML editor in an RTB. I want a Paragraph XAML element to render like this in the RTB:

<p>
  Lorem ipsum stackus overflowum 
</p>

...,运行将显示如下:

... and a Run would render like this:

<span style="font-weight:bold">clarity is important when asking questions</span>

...等等,具有不同的XAML元素。

... and so on with the different XAML elements.

推荐答案

其中一些可以使用样式进行处理

EG

Some of that you can do with styles
E.G.

<Paragraph Style="{StaticResource Par2}">
    This is not a substitute for training.
</Paragraph>

<Style x:Key="Par1short"  TargetType="Paragraph">
    <Setter Property="Margin" Value="15,4,0,0" />
</Style>
<Style x:Key="Par2"  TargetType="Paragraph">
    <Setter Property="Margin" Value="30,7,0,0" />
</Style>
<Style x:Key="Par2short"  TargetType="Paragraph">
    <Setter Property="Margin" Value="30,4,0,0" />
</Style>
<Style x:Key="Par3"  TargetType="Paragraph">
    <Setter Property="Margin" Value="45,7,0,0" />
</Style>
<Style x:Key="Par3short"  TargetType="Paragraph">
    <Setter Property="Margin" Value="45,4,0,0" />
</Style>
<Style x:Key="Par4"  TargetType="Paragraph">
    <Setter Property="Margin" Value="60,7,0,0" />
</Style>
<Style x:Key="Par4short"  TargetType="Paragraph">
    <Setter Property="Margin" Value="60,4,0,0" />
</Style>
<Style x:Key="Par5"  TargetType="Paragraph">
    <Setter Property="Margin" Value="75,7,0,0" />
</Style>
<Style x:Key="Par5short"  TargetType="Paragraph">
    <Setter Property="Margin" Value="75,4,0,0" />
</Style>

现在使用段落一词:在每个段落之前,我都不认为您可以使用样式

Now the word Paragraph: before every paragraph I don't think you can do that with styles

这篇关于WPF FlowDocument ::如何为子段落,运行等定义自定义模板的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆