Hi,
As its calling only first time but not calling again size changing means again docking the toolwindow to otherdocksite that have usercontrol.
For the simple docking application code below.Main application window that consist of docksite which have toolwindow and toolwindow have usercontrol.As shown below View and View2 are the usercontrols and consist of only single button and the OnSizchanged function.
<Grid>
<docking:DockSite x:Name="BaseDocksite2"><docking:Workspace>
<Grid><Grid.RowDefinitions><RowDefinition/><RowDefinition Height="50"/></Grid.RowDefinitions>
<docking:DockSite x:Name="docksite1" Grid.Row="0">
<docking:ToolWindowContainer><docking:ToolWindow><Common:View></Common:View></docking:ToolWindow></docking:ToolWindowContainer>
</docking:DockSite><docking:DockSite x:Name="docksite2" WindowDragging="docksite2_WindowDragging" Grid.Row="1">
<docking:ToolWindowContainer><docking:ToolWindow x:Name="Toowindow2"><Common:View2></Common:View2></docking:ToolWindow></docking:ToolWindowContainer>
</docking:DockSite></Grid></docking:Workspace>
</docking:DockSite>
</Grid>
As view and View2 are same like below
<UserControl x:Class="DockingApplication.View"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"xmlns:Common="clr-namespace:DockingApplication"Common:SizeChangedBehaviour.OnSizeChanged="{Binding UserControlSizeChanged}"><Grid><Button Content="View1" Background="Yellow"></Button></Grid></UserControl>
CodeBehind file for the above consist of tHE OnSizeChanged function whwnever the size of the usercontrol changes.
Size change Behaviour
public class SizeChangedBehaviour{
publicstaticDependencyProperty OnSizeChangedProperty = DependencyProperty.RegisterAttached("OnSizeChanged",typeof(ICommand),typeo(SizeChangedBehaviour),newUIPropertyMetadata(OnSizeChanged));
publicstaticICommand GetOnSizeChanged(DependencyObjecttarget){
return (ICommand)target.GetValue(OnSizeChangedProperty);}
publicstaticvoid SetOnSizeChanged(DependencyObject target, ICommandcommand){
target.SetValue(OnSizeChangedProperty, command);
}
privatestaticvoid OnSizeChanged(DependencyObject target, DependencyPropertyChangedEventArgse){
FrameworkElement ele = target asFrameworkElement;
if (ele != null){
ele.SizeChanged -= SizeChanged;
if (e.NewValue != null){
ele.SizeChanged += SizeChanged;}}}
staticvoid SizeChanged(object sender, SizeChangedEventArgse){
object[] sizeChangeParam = newobject[2];
var frameworkelement = sender asFrameworkElement;
var dpo = e.OriginalSource asDependencyObject;
if (frameworkelement == null || dpo == null)
return;
UIElement uiElement = sender asUIElement;
ICommand command = (ICommand)uiElement.GetValue(OnSizeChangedProperty);sizeChangeParam[0] = sender;
sizeChangeParam[1] = e;
if(command.CanExecute(sizeChangeParam))command.Execute(sizeChangeParam);
(sender
asFrameworkElement).SizeChanged -= SizeChanged;}
}
As the size changes or as i dock the toolwindow ,the command that is UserControlSizeChanged should call that corresponding OnSizeChanged function.
Means
If i dock the toolwindow to the docksite more than one time then function OnSizeChanged calls only first time not every time when user dock the toolwindow.