Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8940863
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T11:09:24+00:00 2026-06-15T11:09:24+00:00

In my application I use a ContentControl and dynamically fill it with a custom

  • 0

In my application I use a ContentControl and dynamically fill it with a custom UserControl, using binding on Content to bind to a FrameworkElement. [EDITED: added example code to show the problem]

After some input of Steven and Charleh I created a small MVVM project to reproduce the problem. My MainWindow now looks like that:

    <Window x:Class="ResizeExample.MainWindow"
    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"
    xmlns:localVM="clr-namespace:ResizeExample.ViewModels"
    xmlns:local="clr-namespace:ResizeExample"
    Title="ResizeExample"
    WindowStartupLocation="CenterScreen"
    Height="459"
    Width="795">
<Window.Resources>
    <localVM:MainWindowViewModel x:Key="Windows1ViewModel" />
</Window.Resources>

<Grid DataContext="{StaticResource Windows1ViewModel}">
    <Grid.RowDefinitions>
        <RowDefinition Height="50" />
        <RowDefinition Height="*" />
    </Grid.RowDefinitions>
    <Canvas Grid.Row="0">
        <Menu DockPanel.Dock="Top"/>
        <Label Content="Any Label on the right side" Canvas.Right="0" Canvas.Bottom="0"/>
    </Canvas>
    <Grid Grid.Row="1" HorizontalAlignment="Stretch"  VerticalAlignment="Stretch">
        <ContentControl Name="ControlCanvas" Content="{Binding Path=externalView}" HorizontalAlignment="Stretch"  VerticalAlignment="Stretch" HorizontalContentAlignment="Stretch"  VerticalContentAlignment="Stretch"/>
    </Grid>
</Grid>

Setting externalView works fine, but it does not resize when the window is resized. Here how I implemented it in the ViewModel:

    private FrameworkElement _externalView;
    public FrameworkElement externalView
    {
        get { return this._externalView; }
        set
        {
            if (this._externalView != value)
            {
                this._externalView = value;
                RaisePropertyChanged(() => externalView);
            }
        }
    }

    public MainWindowViewModel()
    {
        externalView = new UserControl1();
    }

The UserControl contains a TabControl (which should resize) and everything else is in the TabControl. The TabControl contains some labels, text boxes and buttons (which should not resize) and a DataGrid (which should resize). At the moment the complete TabControl is minimized, because no size is set and it will not resize.

<UserControl x:Class="ResizeExample.Views.UserControl1"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
         xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
         xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 
         xmlns:d="http://schemas.microsoft.com/expression/blend/2008" 
         mc:Ignorable="d" 
         d:DesignHeight="411" d:DesignWidth="805" HorizontalAlignment="Stretch"  VerticalAlignment="Stretch" >
<Grid HorizontalAlignment="Stretch"  VerticalAlignment="Stretch"   >
    <TabControl HorizontalAlignment="Left" Name="tabControl1" VerticalAlignment="Top">
        <TabItem Header="Tab1" Name="Tab1">
            <Grid />
        </TabItem>
        <TabItem Header="Tab2" Name="Tab2">
            <Grid>
                <TextBox Height="23" HorizontalAlignment="Left" Margin="6,6,0,0" Name="textBox1" VerticalAlignment="Top" Width="357" />
                <Label Content="Input some data 1:" Height="28" HorizontalAlignment="Left" Margin="6,29,0,0" Name="label1" VerticalAlignment="Top" />
                <Label Content="Input some data 2:" Height="28" HorizontalAlignment="Left" Margin="6,57,0,0" Name="label2" VerticalAlignment="Top" />
                <Label Content="Input some data 3:" Height="28" HorizontalAlignment="Left" Margin="6,85,0,0" Name="label3" VerticalAlignment="Top" />
                <DataGrid AutoGenerateColumns="False" MinHeight="200" HorizontalAlignment="Left" Margin="6,113,0,0" Name="releaseNotesGrid" VerticalAlignment="Top" MinWidth="780" />
            </Grid>
        </TabItem>
    </TabControl>
</Grid>
</UserControl>

I thought the controls would resize automatically, but this is not working. While I’m new to WPF and MVVM, it could be that I missed something basic.

I found the following thread after which I removed the sizes and added the alignments, but this didn’t solve my problem.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-15T11:09:26+00:00Added an answer on June 15, 2026 at 11:09 am

    I solved it now by testing a bit. The problem was the TabControl and DataGrid in the UserControl, which had Alignments that did not work with the stretch. This is now my UserControl1 and it works fine for me:

    <UserControl x:Class="ResizeExample.Views.UserControl1"
            xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
             xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
             xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 
             xmlns:d="http://schemas.microsoft.com/expression/blend/2008" 
             mc:Ignorable="d" HorizontalAlignment="Stretch"  VerticalAlignment="Stretch" HorizontalContentAlignment="Stretch"  VerticalContentAlignment="Stretch">
    <Grid HorizontalAlignment="Stretch"  VerticalAlignment="Stretch" >
        <TabControl HorizontalAlignment="Stretch" Name="tabControl1" VerticalAlignment="Stretch">
            <TabItem Header="Tab1" Name="Tab1">
                <Grid />
            </TabItem>
            <TabItem Header="Tab2" Name="Tab2" VerticalContentAlignment="Stretch" HorizontalContentAlignment="Stretch">
                <Grid>
                    <TextBox Height="23" HorizontalAlignment="Left" Margin="6,6,0,0" Name="textBox1" VerticalAlignment="Top" Width="357" />
                    <Label Content="Input some data 1:" Height="28" HorizontalAlignment="Left" Margin="6,29,0,0" Name="label1" VerticalAlignment="Top" />
                    <Label Content="Input some data 2:" Height="28" HorizontalAlignment="Left" Margin="6,57,0,0" Name="label2" VerticalAlignment="Top" />
                    <Label Content="Input some data 3:" Height="28" HorizontalAlignment="Left" Margin="6,85,0,0" Name="label3" VerticalAlignment="Top" />
                    <DataGrid AutoGenerateColumns="False" MinHeight="200" Margin="6,113,0,0" Name="releaseNotesGrid" HorizontalAlignment="Stretch" VerticalAlignment="Stretch" MinWidth="780" />
                </Grid>
            </TabItem>
        </TabControl>
    </Grid>
    </UserControl>
    

    Thanks to Steven and Charleh to point me to the right direction.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm using Visual Studio to create my installation package. My application use some bitmap
My application use standard search mechanism (using searchable interface) and works well in all
I'm trying to have my custom java application use our Active Directory Server for
I created a custom control and what to use a ContentControl inside that control
I'm very new to WPF and am writing an application using this example as
I would like to use new custom fonts in an android application. please be
Can the application use set same char in the XON and XOFF? If yes,
Somebody said that when your PHP code and application use global variables then it
Based on the following example URL structure: mysite.com/mypage.aspx?a=red&b=green&c=blue Pages in the application use ASP.net
I use application property to count number of online users: Application[OnlineUsers] = (int)Application[OnlineUsers] +

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.