【问题标题】:WPF Xaml control converted to an image has incorrect layout转换为图像的 WPF Xaml 控件布局不正确
【发布时间】:2017-02-01 04:18:08
【问题描述】:

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

Force rendering of a WPF control in memory

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

试过了:

  • 多次拨打UpdateLayout
  • 将控件大小更改 1 个像素
  • 使用 ViewBox

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

<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 编辑器中显示得很好,或者如果它在运行时在真正可见的控件中使用。

【问题讨论】:

    标签: wpf wpf-controls


    【解决方案1】:

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

    在这种情况下,我有一个边框控件 - 所以我必须删除 Visibility 属性并改用这个触发器。

        <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>
    

    【讨论】:

      猜你喜欢
      • 2010-10-04
      • 2010-11-30
      • 1970-01-01
      • 2016-03-17
      • 1970-01-01
      • 2016-08-02
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多