Embed custom control in WPF FlowDocument
Is there any way to embed a custom control into the flowdocument and have it corre开发者_运维技巧ctly displayed by the FlowDocument viewers (export it to Xaml text file and open it by a viewer)?
yes use a BlockUIContainer or InlineUIContainer
<FlowDocument xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:l="clr-namespace:MyNamespace;assembly=MyAssembly">
<BlockUIContainer>
<l:MyCustomControl/>
</BlockUIContainer>
</FlowDocument>
note that wherever your viewer is will need to have access + trust to use the assembly with the custom control in. The easiest way to achieve this is to have the viewer in the same assembly as the the control.
If by custom control you mean UserControl or any custom control inherited from a WPF control, you can't: This custom control is in its own XML namespace, and requires code deployed in an assembly. Your XAML reader won't have access to it when attempting to parse the file, and won't succed.
You can only use controls provided by Microfost, and deployed with the viewer. Maybe it's possible to make viewers know of assemblies deployed in the GAC, but it's a solution only if you can deploy in the client GAC.
精彩评论