转换为图像的 WPF Xaml 控件布局不正确 [英] WPF Xaml control converted to an image has incorrect layout

查看:29
本文介绍了转换为图像的 WPF Xaml 控件布局不正确的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个控件,我正在使用此处的方法将其转换为图像:

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

在内存中强制渲染 WPF 控件

不幸的是,我有一个复杂的布局,似乎折叠"的控件实际上并未正确隐藏在输出图像中.

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

尝试过:

  • 多次调用UpdateLayout
  • 将控件的大小更改 1 个像素
  • 使用视图框

如果某些东西与底部对齐并用转换器隐藏,它似乎会影响 DockPanel.

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>

一切在 Xaml 编辑器中都显示得很好,或者如果它在运行时在真正的可见控件中使用.

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

推荐答案

最后我不得不使用触发器将高度设置为零,而不是将 Collapsed 应用于元素.当然,这意味着任何边距都必须转换为填充,如果需要,可以使用嵌套面板.

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.

在本例中,我有一个边框控件 - 所以我必须删除 Visibility 属性并改用此触发器.

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>

这篇关于转换为图像的 WPF Xaml 控件布局不正确的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆