c# - 具有嵌套宽度/高度的 ContentControl 中的 UserControl

标签 c# xaml windows-store-apps

我正在使用 Caliburn Micro 开发 Windows 应用商店应用程序。

在其中一个页面中,我有 ContentControl,它显示 UserControl。在 UserControl 中,我有 GridView

我的问题是:如何将 UserControl.Width 设置为 ContentControl.Width?
注意:设置 UserControl.Width=Auto - 宽度与 GridView.Width 相同

在 page.xaml 中

<ContentControl x:Name="ActiveItem" />

在 usercontrol.xaml 中

<UserControl
x:Class="Test.Views.GroupView"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
mc:Ignorable="d" Width="Auto" Height="Auto">

    <Grid Margin="0,20">
        <GridView x:Name="Groups" Margin="0" />
    </Grid>
</UserControl>



更新

添加

  VerticalAlignment="Stretch"
  HorizontalAlignment="Stretch"

UserControl 不能解决问题。

最佳答案

经过大量的试验和错误后发现:

<ContentControl Name="MyContent" HorizontalContentAlignment="Stretch" VerticalContentAlignment="Stretch">

关键是使用 Horizo​​ntal/Vertical*Content*Alignment 属性(而不是 Horizo​​ntal/VerticalAlignment 属性)。

关于c# - 具有嵌套宽度/高度的 ContentControl 中的 UserControl,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16479504/

相关文章:

c# - 数据绑定(bind)到以枚举为键的字典中的条目

c# - 如何在 Windows Store 应用程序中编辑和保存照片?

c# - 反向表单点击?

c# - Razor 约定

c# - Xamarin Forms 访问所有 View 模型

c# - 如何通过异步方法有效地更新 UI?

c# - HttpClient 在 POST 期间不传递内容

C#方法获取具有相同属性的类型列表

c# - 数据读取器内的数据读取器

c# - 如何在 Wcf 服务上抛出异常并在客户端捕获它?