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

  • SEARCH
  • Home
  • 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 6810863
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T20:15:26+00:00 2026-05-26T20:15:26+00:00

I have a wpf application using mvvm approach. The main window contains a tab

  • 0

I have a wpf application using mvvm approach. The main window contains a tab control.

Each item within the tab control has its own view model and each tab item contains a wrap panel. I have created an attached property to allow me to bind to the ActualHeight and ActualWidth properties of the panel. (I did not use height/width properties as I need the panel to fill the available space.)

When the window is resized the panel on the active tab is resized however all panels on other tabs are not updated. Watching the bindings only one change is notified.

Is this the expected behaviour using WPF? If not what is wrong with my approach, or if so is there a way to force all the tabs to update?

  • 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-05-26T20:15:27+00:00Added an answer on May 26, 2026 at 8:15 pm

    Each TabItem sounds like it is being drawn separately. Usually WPF unloads TabItems that are not visible, so at the time the Window’s Size changes, there’s only one WrapPanel that exists. When you re-load a TabItem by switching tabs, if something is not bound (such as the ActualHeight), then it will reload to its original values defined in your XAML

    Usually I prefer to store my sizes as a percentage, and then use a Converter to convert the percentage to an actual size

    The converter I usually use is below. I’m created this when I first started with WPF, and I wasn’t aware there were MultiConverters at the time. I’m sure it could be re-written to be a multi-converter, however I’ve never gotten around to doing it yet.

    To use it, add your converter to your Resources

    <local:PercentOfParentConverter x:Key="PanelHeightConverter" />
    <local:PercentOfParentConverter x:Key="PanelWidthConverter" />
    

    Set your bindings based on the Converter

    <Setter Property="Height" Value="{Binding Path=PanelHeight, 
                Converter={StaticResource PanelHeightConverter}}" />
    <Setter Property="Width" Value="{Binding Path=PanelWidth, 
                Converter={StaticResource PanelWidthConverter}}" />
    

    And in the Code-Behind, be sure to hook into the SizeChanged event to update the converter’s ParentSize whenever the size changes

    // If workarea size changes, reposition/resize panels within it to keep the same layout
    private void PanelSizeChanged(object sender, SizeChangedEventArgs e)
    {
        Panel c = sender as Panel;
        if (c != null)
        {
            // Set the parent's height/width on the converter
            PercentOfParentConverter sizeConverter = (PercentOfParentConverter)c.FindResource("PanelHeightConverter");
            if (sizeConverter != null) sizeConverter.ParentSize = c.ActualHeight;
    
            sizeConverter = (PercentOfParentConverter)c.FindResource("PanelWidthConverter");
            if (sizeConverter != null) sizeConverter.ParentSize = c.ActualWidth;
    
            foreach (UIElement child in c.Children)
            {
                RebindPanelSizeAndPosition(child);
            }
        }
    }
    
    // Refreshes the Panel.Height/Width bindings of the UIElement passed to it
    private void RebindPanelSizeAndPosition(UIElement element)
    {
        BindingOperations.GetBindingExpressionBase(element, Panel.HeightProperty).UpdateTarget();
        BindingOperations.GetBindingExpressionBase(element, Panel.WidthProperty).UpdateTarget();
    }
    

    The actual converter code looks like this:

    // Converts a percent to a double value based on the parent size set
    public class PercentOfParentConverter : IValueConverter
    {
        public double ParentSize { get; set; }
    
        #region IValueConverter Members
    
        public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
        {
            var percent = (double) value;
            return percent*ParentSize;
        }
    
        public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
        {
            if (ParentSize != 0)
            {
                return (double) value/ParentSize;
            }
            else
            {
                return 0;
            }
        }
    
        #endregion
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm developing a WPF application using MVVM. Inside a Window, I have a control
I'm using MVVM in my WPF application. I have a Window that has a
I have a C# WPF application using a rather noddy MVVM approach. In one
I have a WPF application using MVVM. I have some user controls that show
I have a WPF application implemented using the MVVM framework that uses an ActiveX
I am coding a WPF application using MVVM pattern. I don't need to have
I'm writting an WPF application using the mvvm toolkint. In the main windows I
I am using MVVM architecture to develop a WPF application... So far everything has
I've got a WPF MVVM application. One of my views has a user control
I'm writing an application using WPF MVVM. I have a view model with property

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.