在我的MVVM WPF應用程序中,我使用了一個數據綁定flowdocument。我使用描述的技術here能夠將我的數據綁定到flowdocument。 我的flowdocument綁定到我的viewmodel中的公共屬性。屬性是一個IEnumerable自定義類型的,例如:在數據綁定中插入分隔符(空白行)flowdocument
public IEnumerable<Person> Persons
{
get { return _persons; }
set { _persons = value; }
}
所述的FlowDocument以FlowDocumentScrollViewer控制所示。該文件看起來像:
code name lastname
---- ----- ---------
1 john johnson
1 peter peterson
2 jane jane
3 john doe
精細的綁定工作,但是我想每個不同的代碼後添加一個空行:
code name lastname
---- ----- ---------
1 john johnson
1 peter peterson
2 jane jane
3 john doe
我的XAML中的觀點是:
<FlowDocumentScrollViewer>
<FlowDocument>
<flowdoc:ItemsContent ItemsSource="{Binding Path=Persons}">
<flowdoc:ItemsContent.ItemsPanel>
<DataTemplate>
<flowdoc:Fragment>
<Table BorderThickness="1" BorderBrush="Black">
<TableRowGroup flowdoc:Attached.IsItemsHost="True">
<TableRow Background="LightBlue">
<TableCell>
<Paragraph>ronde</Paragraph>
</TableCell>
<TableCell>
<Paragraph>hal</Paragraph>
</TableCell>
<TableCell>
<Paragraph>datum</Paragraph>
</TableCell>
</TableRow>
</TableRowGroup>
</Table>
</flowdoc:Fragment>
</DataTemplate>
</flowdoc:ItemsContent.ItemsPanel>
<flowdoc:ItemsContent.ItemTemplate>
<DataTemplate>
<flowdoc:Fragment>
<TableRow>
<TableCell>
<Paragraph>
<flowdoc:BindableRun BoundText="{Binding Path=Code}" />
</Paragraph>
</TableCell>
<TableCell>
<Paragraph>
<flowdoc:BindableRun BoundText="{Binding Path=Name}" />
</Paragraph>
</TableCell>
<TableCell>
<Paragraph>
<flowdoc:BindableRun BoundText="{Binding Path=LastName}" />
</Paragraph>
</TableCell>
</TableRow>
</flowdoc:Fragment>
</DataTemplate>
</flowdoc:ItemsContent.ItemTemplate>
</flowdoc:ItemsContent>
有關如何在不破壞MVVM規則的情況下做到這一點的任何建議?數據綁定流程文檔似乎與不靈活佈局的價格相關。
在此先感謝
我想你提到的應該是[創建靈活的用戶界面隨着流量的文件和數據綁定]鏈接(http://msdn.microsoft.com/en-我們/雜誌/ dd569761.aspx)。 – 2012-07-05 07:02:27
是的,你說得對。這是正確的聯繫。我剛剛糾正了上面的鏈接。謝謝! – svr