【问题标题】:WPF UserControl fill ContentControl with fixed width and heightWPF UserControl 用固定的宽度和高度填充 ContentControl
【发布时间】:2017-04-18 17:52:54
【问题描述】:

我有想要在 ContentControl 中显示的用户控件。所以我做了什么(这只是我拥有的一个 UserControl):

<UserControl.Resources>
    <DataTemplate x:Key="Suburb" DataType="{x:Type local:ViewSuburb}">
        <local:ViewSuburb Width="Auto" Height="Auto" />
    </DataTemplate>
</UserControl.Resources>

<ContentControl Grid.Column="1" Grid.Row="1" ContentTemplate="{StaticResource Suburb}">
</ContentControl>

(ViewSuburb Width="Auto" Height="Auto" 无效)

我的问题是 ViewSuburb 仅用作弹出对话框,因此在其 .xaml 中我给它一个固定的宽度和高度。如果我将宽度和高度设置为自动,那么它在 ContentControl 中很好并相应地拉伸,但它会在屏幕上拉伸弹出窗口。因为我给了它固定的宽度和高度,所以弹出窗口很好,但在 ContentControl 中它也有固定的宽度和高度。

有没有办法可以覆盖 SuburbView 的宽度和高度,或者如果我将其设置为自动,弹出窗口不会在屏幕上伸展?

谢谢。

【问题讨论】:

  • 您是否尝试在 SuburbView 上设置 MaxWidth 和 MaxHeigth,这样它就不会超出最大值。
  • 是的,那么它在 ContentControl 中的大小是固定的。
  • 设置弹出/窗口的宽度/高度。
  • @mm8 谢谢你的窍门,你能不能把它作为答案,所以我可以接受它作为答案。

标签: wpf user-controls


【解决方案1】:

您应该设置Popup/WindowWidth/Height,即ContentControl 的父级。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-01-12
    • 2022-01-20
    • 2017-06-07
    • 1970-01-01
    • 2021-06-16
    • 1970-01-01
    相关资源
    最近更新 更多