XAML ContentControl 子项未拉伸以填充 ContentControl

dev*_*os1 1 xaml uwp

我有一件非常简单的事情,我正在尝试做,但它不起作用,我试图了解我错过了什么。

所以我<ContentControl>在父 UI 中有一个,并将其Content属性绑定到控制器上的 DependencyProperty:

<ContentControl x:Name="rightPanel">
Run Code Online (Sandbox Code Playgroud)

(它位于行高设置为 的 Grid 内*。)

然后我实例化一个包含 Grid 的 UserControl(因此应该拉伸以填充可用空间),但是每当我将它嵌入到 UserControl 中时,它就会失去所有“拉伸”并开始缩小,就像它在 StackPanel 中一样。

<UserControl
    *namespace snip*>
    <Grid Background="LightGreen">
        <TextBlock Text="Oh happy days..."/>
    </Grid>
</UserControl>
Run Code Online (Sandbox Code Playgroud)

var innerPage = new MyUserControl1(); // the above <UserControl>
this.rightPanel.Content = innerPage;
Run Code Online (Sandbox Code Playgroud)

在此处输入图片说明

我不明白为什么会这样。我用UserControls 和Pages都试过了,没有区别。我错过了什么?

ibe*_*bbs 5

将 ContentControl 的 Horizo​​ntalContentAlignment / VerticalContentAlignment 设置为 Stretch。