Search code examples
c#xamlwindows-store-apps

UserControl inside ContentControl with nested width/height


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

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

in page.xaml

<ContentControl x:Name="ActiveItem" />

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>



UPDATE

Adding

  VerticalAlignment="Stretch"
  HorizontalAlignment="Stretch"

To UserControl doesn't solve the problem.


Solution

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

    In root Page you have:

     <ContentControl x:Name="ActiveItem"/>
    

    Then add the child page:

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

    And that's all.