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?
Each
TabItemsounds 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 XAMLUsually 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
Set your bindings based on the Converter
And in the Code-Behind, be sure to hook into the
SizeChangedevent to update the converter’sParentSizewhenever the size changesThe actual converter code looks like this: