如何以样式设置 FlowDocument 的 Table.Columns
我有多个 FlowDocument,它们都有一个表。所有表格看起来都一样。
所以我想重构 FlowDocument 。
我的初始文档如下所示:
<FlowDocument xmlns=...>
<Table>
<Table.Columns>
<TableColumn Width="12*" />
<TableColumn Width="1.5*" />
<TableColumn Width="2*" />
<TableColumn Width="*" />
<TableColumn Width="2*" />
<TableColumn Width="*" />
</Table.Columns>
<TableRowGroup>
<TableRow>
<TableCell>Some content...</TableCell>
...
</Table>
</FlowDocument>
我正在寻找类似的内容:
<FlowDocument xmlns=...>
<FlowDocument.Resources>
<Style TargetType="{x:Type Table}">
<Setter Property="ColumnsDefinition">
<Setter.Value>
<ControlTemplate>
<TableColumn Width="12*" />
<TableColumn Width="1.5*" />
<TableColumn Width="2*" />
<TableColumn Width="*" />
<TableColumn Width="2*" />
<TableColumn Width="*" />
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
</FlowDocument.Resources>
<Table>
<TableRowGroup>
<TableRow>
<TableCell>Some content...</TableCell>
...
</Table>
</FlowDocument>
但不幸的是 FlowDocuments 表没有属性 Template
。
I have multiple FlowDocument
s, all of them have a table. All tables look the same.
So I want to refactor the FlowDocument
s.
My initial document looks like:
<FlowDocument xmlns=...>
<Table>
<Table.Columns>
<TableColumn Width="12*" />
<TableColumn Width="1.5*" />
<TableColumn Width="2*" />
<TableColumn Width="*" />
<TableColumn Width="2*" />
<TableColumn Width="*" />
</Table.Columns>
<TableRowGroup>
<TableRow>
<TableCell>Some content...</TableCell>
...
</Table>
</FlowDocument>
I'm looking for something like:
<FlowDocument xmlns=...>
<FlowDocument.Resources>
<Style TargetType="{x:Type Table}">
<Setter Property="ColumnsDefinition">
<Setter.Value>
<ControlTemplate>
<TableColumn Width="12*" />
<TableColumn Width="1.5*" />
<TableColumn Width="2*" />
<TableColumn Width="*" />
<TableColumn Width="2*" />
<TableColumn Width="*" />
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
</FlowDocument.Resources>
<Table>
<TableRowGroup>
<TableRow>
<TableCell>Some content...</TableCell>
...
</Table>
</FlowDocument>
But unfortunately the FlowDocuments Table doesn't have a property Template
.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
不幸的是,Columns 属性是只读集合属性,因此您可以在 XAML 中添加它,但不能从 Setter 中设置它。解决此问题的一种方法是创建一个可以设置的附加属性,然后将值从附加属性传输到集合。例如:
然后在 XAML 中:
Unfortunately, the Columns property is a read-only collection property, so you can add to it in XAML but you can't set it from a Setter. One way around this problem is to create an attached property that you can set, and then transfer the values from the attached property to the collection. For example:
And then in XAML: