WPF UserControl 用固定的宽度和高度填充 ContentControl

WPF UserControl fill ContentControl with fixed width and height

我有要在 ContentControl 中显示的 UserControl。所以我做了什么(这只是一个 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 的宽度和高度,或者如果我将其设置为自动弹出窗口不会横跨屏幕?

谢谢。

您应该设置 Popup/WindowWidth/HeightContentControl 的父级。