具有嵌套宽度/高度的 ContentControl 内的 UserControl [英] UserControl inside ContentControl with nested width/height

查看:25
本文介绍了具有嵌套宽度/高度的 ContentControl 内的 UserControl的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I'm developing Windows Store App with using Caliburn Micro.

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

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

In one of the pages I have ContentControl, which display UserControl. In UserControl I have GridView.

My question is: How to set UserControl.Width same as ContentControl.Width?
Note: whet set UserControl.Width=Auto - width the same as GridView.Width

在 page.xaml 中

in page.xaml

<ContentControl x:Name="ActiveItem" />

在 usercontrol.xaml 中

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

To UserControl 不能解决问题.

To UserControl doesn't solve the problem.

推荐答案

特别是@AlexeiMalashkevich
我使用这样的绑定来解决它:

Especially for @AlexeiMalashkevich
I solve it with using binding like this:

在根页面中,您有:

In root Page you have:

 <ContentControl x:Name="ActiveItem"/>

然后添加子页面:

<Page
    Height="{Binding ActualHeight, ElementName=ActiveItem}"
    Width="{Binding ActualWidth, ElementName=ActiveItem}"
    ......
/>

仅此而已.

这篇关于具有嵌套宽度/高度的 ContentControl 内的 UserControl的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆