【发布时间】:2011-09-25 04:05:33
【问题描述】:
我在启动打印过程时丢失了数据绑定,这可能吗?这就是我在我这里的情况下只能想到的,我在一个控件中有一个 Table,它使 Table 数据可绑定,所有这些都在 FlowDocument 内。运行它时,数据绑定工作正常,表格自己绘制了一些数据,没有问题。
但是,当打印该控件的输出时总是空白。
我添加了具有相同绑定的ListView,并且在打印生成的数据时它也似乎丢失了。
XAML:
<Window x:Class="GlassStore.InitBill"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="clr-namespace:GlassStore.ViewModels"
xmlns:flowdocs="clr-namespace:FlowDocuments;assembly=FlowDocument"
Title="InitBill" Height="825" Width="1004">
<Window.DataContext>
<local:InitBillViewModel/>
</Window.DataContext>
<Grid Background="White">
<FlowDocumentReader HorizontalAlignment="Center"
HorizontalContentAlignment="Center">
<FlowDocument ColumnWidth="999999"
IsColumnWidthFlexible="True"
TextAlignment="Center"
Name="FD">
<Paragraph>
<ListView ItemsSource="{Binding GridTrans}">
<ListView.View>
<GridView>
<GridViewColumn Header="ffff"
DisplayMemberBinding="{Binding CarModel}" />
<GridViewColumn Header="xxxx"
DisplayMemberBinding="{Binding CarName}" />
</GridView>
</ListView.View>
</ListView>
</Paragraph>
<Paragraph TextAlignment="Center">
<TextBlock Text="{Binding test}" />
</Paragraph>
<flowdocs:ItemsContent ItemsSource="{Binding GridTrans}"
Background="#FFF2C3C3"
BorderThickness="2">
<flowdocs:ItemsContent.ItemTemplate>
<DataTemplate>
<flowdocs:Fragment>
<Table>
<TableRowGroup flowdocs:Attached.IsItemsHost="True">
<TableRow Background="AliceBlue" >
<TableCell Foreground="Red">
<Paragraph>
<flowdocs:BindableRun BoundText="{Binding CarName}" />
</Paragraph>
</TableCell>
<TableCell Foreground="Green">
<Paragraph>
<flowdocs:BindableRun BoundText="{Binding CarModel}" />
</Paragraph>
</TableCell>
<TableCell Foreground="Yellow">
<Paragraph>
<flowdocs:BindableRun BoundText="{Binding glassPrice}" />
</Paragraph>
</TableCell>
</TableRow>
</TableRowGroup>
</Table>
</flowdocs:Fragment>
</DataTemplate>
</flowdocs:ItemsContent.ItemTemplate>
</flowdocs:ItemsContent>
<Table>
<TableRowGroup>
<TableRow>
<TableCell>
<Paragraph>Row1 Cell1</Paragraph>
</TableCell>
<TableCell>
<Paragraph>Row2 Cell2</Paragraph>
</TableCell>
</TableRow>
</TableRowGroup>
</Table>
</FlowDocument>
</FlowDocumentReader>
<Button Command="{Binding print}"
Content="إطـبع"
Height="29" Margin="91,0,112,41"
Name="button1"
VerticalAlignment="Bottom" />
</Grid>
</Window>
现在我知道问题不在于自定义控件,因为我现在与 ListView 有同样的问题。
【问题讨论】:
-
一些代码会很好。
-
我和@Femaref 在一起,我们需要查看一些 XAML 以及可能与它相关的任何代码。
-
添加了 XAML ,我没有代码隐藏,因为我遵循 MVVM 模式,我有一个 viewModel 代替,先看图片,如果需要 viewModel ,我将添加它也是
-
我们能看到打印命令的代码吗?
标签: wpf data-binding .net-3.5 printing flowdocument