I've a window that opens on a button click:
previewWindow = new UsrCntrls.PreviewWindow();
previewWindow.DataContext = this;
previewWindow.Show();
and has these on xaml:
<Window x:Class="Client.UsrCntrls.PreviewWindow"
...>
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="Auto"/>
<RowDefinition Height="*"/>
</Grid.RowDefinitions>
<Button Content="Print" Command="{Binding Print}"/>
<!--<FlowDocumentReader Document="{Binding Doc}" Grid.Row="1"/>-->
<FlowDocumentPageViewer Document="{Binding Doc}" Grid.Row="1"/>
</Grid>
</Window>
With FlowDocumentPageViewer
in Grid.Row=1
I can open and close this window as many time as I want without any problem. If I use FlowDocumentReader
instead of FlowDocumentPageViewer
I can open and close it only once without problem. When I click on the button second time to reopen it, I get this error:
System.InvalidOperationException: 'Specified element is already the logical child of another element. Disconnect it first.'
How to solve this pproblem?
The solution is:
<FlowDocumentReader Document="{Binding Doc, Mode=OneTime}" Grid.Row="1"/>
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.