WPF Xaml control converted to an image has incorre

2019-03-03 23:37发布

I have a control that I am converting to an image using the method here :

Force rendering of a WPF control in memory

Unfortunately I have a complex layout and it seems that a control being 'Collapsed' isn't actually being hidden properly in the output image.

Tried:

  • Call UpdateLayout multiple times
  • Change size of control by 1 pixel
  • Using a ViewBox

It seems to affect DockPanel if something is aligned to the bottom and hidden with a converter.

<DockPanel LastChildFill=True>
    <Something Dock.Panel="Top" />
    <Something Dock.Panel="Bottom" Binding="{Binding XXXXX, Converter={StaticResource booleanConverter}}"/>
    <Something Dock.Panel="Bottom" Binding="{Binding YYYYY, Converter={StaticResource booleanConverter}}"/>
    <Something />
</DockPanel>

Everything displays just fine in the Xaml editor, or if it is used at runtime in a real visible control.

1条回答
贼婆χ
2楼-- · 2019-03-04 00:17

In the end I had to use a trigger to set the height to zero instead of applying Collapsed to the elements. Of course this means any margins must be converted to padding, with nested panels if needed.

In this instance I had a border control - so I had to remove the Visibility property and use this trigger instead.

    <Border>
        <Border.Style>
            <Style>
                <Style.Triggers>
                    <DataTrigger Binding="{Binding XXXXX, Converter={StaticResource booleanConverter}}" Value="true">
                        <Setter Property="Border.Height" Value="0" />
                    </DataTrigger>
                </Style.Triggers>
            </Style>
        </Border.Style>
    </Border>
查看更多
登录 后发表回答