We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy. Image for the cookie policy date
Unfortunately, activation email could not send to your email. Please try again.
Syncfusion Feedback

Command to notify the State changing of MDI window in DocumentContainer

Platform: WPF |
Control: DocumentContainer

 

DocumentContainer have routed event for StateChanged and not have any routed event for StateChanging. But this can be achieved by customizing the Header style of the DocumentWindow. In below code example, new command(“WindowStateChangedCommand”) is binded in customized header style of DocumentMDIHeader. ExecuteWindowStateChange method will be triggered while pressing the Maximize button of MDI Window.

 

DocumentMDIHeader Style:

 

                <Style TargetType="{x:Type syncfusion:DocumentHeader}" x:Key="ModifiedDocumentHeaderStyle">
                    <Setter Property="FocusVisualStyle" Value="{x:Null}" />
                    <Setter Property="BorderBrush" Value="{StaticResource Aero.ActiveHeaderBrush}"/>
                    <Setter Property="Background" Value="{StaticResource Aero.ActiveHeaderBrush}"/>
                    <Setter Property="Foreground" Value="{StaticResource Aero.ActiveForeground}"/>
                    <Setter Property="Border.CornerRadius" Value="3,3,0,0"/>
                    <Setter Property="CloseButtonStyle" Value="{StaticResource HeaderThemedCloseButtonStyle}"/>
                    <Setter Property="MaximizeButtonStyle" Value="{StaticResource HeaderThemedButtonStyle}"/>
                    <Setter Property="MinimizeButtonStyle" Value="{StaticResource HeaderThemedButtonStyle}"/>
                    <Setter Property="RestoreButtonStyle" Value="{StaticResource HeaderThemedButtonStyle}"/>
                    <Setter Property="Template">
                        <Setter.Value>
                            <ControlTemplate TargetType="{x:Type syncfusion:DocumentHeader}">
                                <syncfusion:Border3D Name="Border" 
                         Padding="{TemplateBinding Padding}"
                         BorderThickness="{TemplateBinding BorderThickness}"
                         CornerRadius="{TemplateBinding Border.CornerRadius}"
                         BorderBrush="{TemplateBinding BorderBrush}"
                         Background="{TemplateBinding Background}"
                         >
                                    <DockPanel LastChildFill="True" VerticalAlignment="{TemplateBinding VerticalAlignment}">
                                        <Button Name="btnClose" DockPanel.Dock="Right" Margin="2,2,2,2"
                    Visibility="{syncfusion:ContainerButtonVisibility}"
                    Command="{x:Static syncfusion:DocumentContainer.HideDocumentCommand}"
                    CommandTarget="{syncfusion:FindWindow}"
                    Style="{TemplateBinding CloseButtonStyle}">
                                            <Border Name="btnCloseBorder" Height="10" Width="10" SnapsToDevicePixels="True">
                                                <syncfusion:DrawingHelper Name="btnCloseHelper" DrawingBrush="{StaticResource brushCloseButtonWhite}" />
                                            </Border>
                                        </Button>
                                        <Button Name="btnMaximize" DockPanel.Dock="Right" Margin="0,2,0,2"
                    Visibility="{syncfusion:ContainerButtonVisibility}"
                   Command="{Binding WindowStateChangedCommand}" CommandTarget="{syncfusion:FindWindow}" CommandParameter="{Binding RelativeSource={RelativeSource Mode=FindAncestor, AncestorType=syncfusion:MDIWindow}}"
                    Style="{TemplateBinding MaximizeButtonStyle}">
                                            <Border Name="btnMaximizeBorder" Height="10" Width="10" SnapsToDevicePixels="True">
                                                <syncfusion:DrawingHelper Name="btnMaximizeHelper" DrawingBrush="{StaticResource brushMaximizeButtonVista}" />
                                            </Border>
                                        </Button>
                                        <Button Name="btnRestore" DockPanel.Dock="Right" Margin="0,2,2,2"
                        Visibility="Collapsed"
                        Command="{x:Static syncfusion:DocumentContainer.RestoreDocumentCommand}"
                        CommandTarget="{syncfusion:FindWindow}"
                        Style="{TemplateBinding RestoreButtonStyle}" >
                                            <Border Name="btnRestoreBorder" Height="10" Width="10" SnapsToDevicePixels="True">
                                                <syncfusion:DrawingHelper Name="btnRestoreHelper" DrawingBrush="{StaticResource brushRestoreButtonVista}" />
                                            </Border>
                                       </Button>
                                        <Button Name="btnMinimize" DockPanel.Dock="Right" Margin="2,2,0,2"
                    Visibility="{syncfusion:ContainerButtonVisibility}"
                    Command="{x:Static syncfusion:DocumentContainer.MinimizeDocumentCommand}"
                    CommandTarget="{syncfusion:FindWindow}"
                    Style="{TemplateBinding MinimizeButtonStyle}">
                                            <Border Name="btnMinimizeBorder" Height="10" Width="10" SnapsToDevicePixels="True">
                                                <syncfusion:DrawingHelper Name="btnMinimizeHelper" DrawingBrush="{StaticResource brushMinimizeButtonVista}" />
                                            </Border>
                                        </Button>
                                        <Border Name="IconBorder"  Width="{Binding Path=IconSize, Converter={StaticResource SizeToDoubleConverter}, ConverterParameter=width, RelativeSource={RelativeSource TemplatedParent}}"
                                        Height="{Binding Path=IconSize, Converter={StaticResource SizeToDoubleConverter}, ConverterParameter=height, RelativeSource={RelativeSource TemplatedParent}}"
                                       DockPanel.Dock="Left" Background="{TemplateBinding Icon}" Margin="1" />
                                        <ContentPresenter Content="{TemplateBinding Header}" Name="content"
                              ContentTemplate="{TemplateBinding HeaderTemplate}"
                              VerticalAlignment="Center"
                              TextBlock.Foreground="{TemplateBinding Foreground}"
                              ContentTemplateSelector="{StaticResource DocumentHeaderTrimmingTemplate}"
                                      />
                                    </DockPanel>
 
                                </syncfusion:Border3D>
                                <ControlTemplate.Triggers>
                                    <DataTrigger Binding="{Binding Path=IsActive, RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type syncfusion:MDIWindow}}}" Value="False">
                                        <Setter Property="Background" Value="{StaticResource Aero.InactiveHeaderBrush}"/>
                                        <Setter Property="Foreground" Value="{StaticResource Aero.InactiveForeground}"/>
                                        <Setter Property="BorderBrush" Value="{StaticResource Aero.InactiveHeaderBrush}"/>
                                        <Setter Property="Style" TargetName="btnClose" Value="{StaticResource HeaderThemedCloseButtonStyle}"/>
                                        <Setter Property="Style" TargetName="btnMaximize" Value="{StaticResource HeaderThemedButtonStyle}"/>
                                        <Setter Property="Style" TargetName="btnMinimize" Value="{StaticResource HeaderThemedButtonStyle}"/>
                                        <Setter Property="Style" TargetName="btnRestore" Value="{StaticResource HeaderThemedButtonStyle}"/>
                                    </DataTrigger>
                                    <DataTrigger Binding="{Binding ElementName=IconBorder, Path=(syncfusion:DocumentContainer.Icon)}" Value="{x:Null}">
                                        <Setter TargetName="IconBorder" Property="Visibility" Value="Collapsed"/>
                                    </DataTrigger>
                                    <DataTrigger Binding="{Binding Path=Content.(syncfusion:DocumentContainer.MDIWindowState),
                     RelativeSource={RelativeSource FindAncestor
                        , AncestorType={x:Type syncfusion:MDIWindow}}}" Value="Minimized" >
                                        <Setter TargetName="btnMinimize" Property="Visibility" Value="Collapsed" />
                                        <Setter TargetName="btnRestore" Property="Visibility" Value="{syncfusion:ContainerButtonVisibility}" />
                                        <Setter TargetName="btnMinimizeHelper" Property="Margin" Value="0, 1, 0, 0" />
                                        <Setter TargetName="btnMaximizeHelper" Property="Margin" Value="0, 1, 0, 0" />
                                        <Setter TargetName="btnRestoreHelper" Property="Margin" Value="0, 1, 0, 0" />
                                        <Setter TargetName="btnCloseHelper" Property="Margin" Value="0, 1, 0, 0" />
                                    </DataTrigger>
 
                                    <!--btnMinimize-->
                                    <MultiDataTrigger>
                                        <MultiDataTrigger.Conditions>
                                            <Condition Binding="{Binding Path=IsActive, RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type syncfusion:MDIWindow}}}" Value="True" />
                                            <Condition Binding="{Binding Path=IsEnabled, ElementName=btnMinimize}" Value="True" />
                                        </MultiDataTrigger.Conditions>
                                        <Setter TargetName="btnMinimizeHelper" Property="DrawingBrush" Value="{StaticResource brushMinimizeButtonVista}"/>
                                    </MultiDataTrigger>
                                    <MultiTrigger>
                                        <MultiTrigger.Conditions>
                                            <Condition SourceName="btnMinimize" Property="IsEnabled" Value="True"/>
                                            <Condition SourceName="btnMinimize" Property="IsPressed" Value="True"/>
                                        </MultiTrigger.Conditions>
                                        <Setter TargetName="btnMinimizeHelper" Property="DrawingBrush" Value="{StaticResource brushMinimizeButtonVista}"/>
                                    </MultiTrigger>
                                    <Trigger SourceName="btnMinimize" Property="IsEnabled" Value="False">
                                        <Setter TargetName="btnMinimizeHelper" Property="DrawingBrush" Value="{StaticResource brushMinimizeButtonGray}"/>
                                    </Trigger>
 
                                    <!--btnMaximize-->
                                    <MultiDataTrigger>
                                        <MultiDataTrigger.Conditions>
                                            <Condition Binding="{Binding Path=IsActive, RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type syncfusion:MDIWindow}}}" Value="True" />
                                            <Condition Binding="{Binding Path=IsEnabled, ElementName=btnMaximize}" Value="True" />
                                        </MultiDataTrigger.Conditions>
                                        <Setter TargetName="btnMaximizeHelper" Property="DrawingBrush" Value="{StaticResource brushMaximizeButtonVista}"/>
                                    </MultiDataTrigger>
                                    <MultiTrigger>
                                       <MultiTrigger.Conditions>
                                            <Condition SourceName="btnMaximize" Property="IsEnabled" Value="True"/>
                                            <Condition SourceName="btnMaximize" Property="IsPressed" Value="True"/>
                                        </MultiTrigger.Conditions>
                                        <Setter TargetName="btnMaximizeHelper" Property="DrawingBrush" Value="{StaticResource brushMaximizeButtonVista}"/>
                                    </MultiTrigger>
                                    <Trigger SourceName="btnMaximize" Property="IsEnabled" Value="False">
                                        <Setter TargetName="btnMaximizeHelper" Property="DrawingBrush" Value="{StaticResource brushMaximizeButtonGray}"/>
                                    </Trigger>
                                    <!--btnRestore-->
                                    <MultiDataTrigger>
                                        <MultiDataTrigger.Conditions>
                                            <Condition Binding="{Binding Path=IsActive, RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type syncfusion:MDIWindow}}}" Value="True" />
                                            <Condition Binding="{Binding Path=IsEnabled, ElementName=btnRestore}" Value="True" />
                                        </MultiDataTrigger.Conditions>
                                        <Setter TargetName="btnRestoreHelper" Property="DrawingBrush" Value="{StaticResource brushRestoreButtonVista}"/>
                                    </MultiDataTrigger>
                                    <MultiTrigger>
                                        <MultiTrigger.Conditions>
                                            <Condition SourceName="btnRestore" Property="IsEnabled" Value="True"/>
                                            <Condition SourceName="btnRestore" Property="IsPressed" Value="True"/>
                                        </MultiTrigger.Conditions>
                                        <Setter TargetName="btnRestoreHelper" Property="DrawingBrush" Value="{StaticResource brushRestoreButtonVista}"/>
                                    </MultiTrigger>
                                    <Trigger SourceName="btnRestore" Property="IsEnabled" Value="False">
                                        <Setter TargetName="btnRestoreHelper" Property="DrawingBrush" Value="{StaticResource brushRestoreButtonGray}"/>
                                    </Trigger>
                                    <!--btnClose-->
                                    <MultiDataTrigger>
                                        <MultiDataTrigger.Conditions>
                                            <Condition Binding="{Binding Path=IsActive, RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type syncfusion:MDIWindow}}}" Value="True" />
                                            <Condition Binding="{Binding Path=IsEnabled, ElementName=btnClose}" Value="True" />
                                        </MultiDataTrigger.Conditions>
                                        <Setter TargetName="btnCloseHelper" Property="DrawingBrush" Value="{StaticResource brushCloseButtonWhite}"/>
                                    </MultiDataTrigger>
                                    <MultiTrigger>
                                        <MultiTrigger.Conditions>
                                            <Condition SourceName="btnClose" Property="IsEnabled" Value="True"/>
                                            <Condition SourceName="btnClose" Property="IsPressed" Value="True"/>
                                        </MultiTrigger.Conditions>
                                        <Setter TargetName="btnCloseHelper" Property="DrawingBrush" Value="{StaticResource brushCloseButtonWhite}"/>
                                    </MultiTrigger>
                                    <Trigger SourceName="btnClose" Property="IsEnabled" Value="False">
                                        <Setter TargetName="btnCloseHelper" Property="DrawingBrush" Value="{StaticResource brushCloseButtonGray}"/>
                                    </Trigger>
                                </ControlTemplate.Triggers>
                            </ControlTemplate>
                        </Setter.Value>
                    </Setter>
                    <Setter Property="Icon" Value="{Binding Path=(syncfusion:DocumentContainer.Icon)}"/>
                    <Setter Property="Header" Value="{Binding Path=(syncfusion:DocumentContainer.Header)}"/>
                    <Setter Property="HeaderTemplate" Value="{Binding Path=(syncfusion:MDIWindow.Content).(syncfusion:DocumentContainer.HeaderTemplate), RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type syncfusion:MDIWindow}}}"/>
                </Style>
 
 

 

 

MainWindow.xaml:

 

 

<syncfusion:DocumentContainer Mode="MDI" Name="Doc">
            <ContentControl x:Name="Content1" syncfusion:DockingManager.Header="Document1" syncfusion:DockingManager.State="Document" 
                                                             syncfusion:DocumentContainer.DocumentMDIHeaderStyle="{StaticResource ModifiedDocumentHeaderStyle}"/>
        </syncfusion:DocumentContainer>

 

 

MainWindow.cs :

 

    public partial class MainWindow : Window
    {
        public MainWindow()
        {
            InitializeComponent();
            DataContext = this;
        }
       
        private ICommand windowstatechangedcommand;
        public ICommand WindowStateChangedCommand
        {
            get
            {
                if (windowstatechangedcommand == null)
                {
                    windowstatechangedcommand = new DelegateCommand(ExecuteWindowStateChange, CanExecute);
                }
 
                return windowstatechangedcommand;
            }
            set
            {
                windowstatechangedcommand = value;
            }
        }
 
        private bool CanExecute(object arg)
        {            
            return (Doc != null && Doc.CanMDIMaximize && !Doc.IsInMDIMaximizedState && Doc.Mode == DocumentContainerMode.MDI);
 
        }
 
        private void ExecuteWindowStateChange(object obj)
        {
            DocumentContainer.SetMDIWindowState(obj as DependencyObject, MDIWindowState.Maximized);
            MessageBox.Show("Window is maximized");
        }        
    }  

 

 

Sample link :

https://www.syncfusion.com/downloads/support/directtrac/general/ze/DocumentContainer_StateChange_Notification-1966560593.zip

 

2X faster development

The ultimate WPF UI toolkit to boost your development speed.
ADD COMMENT
You must log in to leave a comment

Please sign in to access our KB

This page will automatically be redirected to the sign-in page in 10 seconds.

Up arrow icon

Warning Icon You are using an outdated version of Internet Explorer that may not display all features of this and other websites. Upgrade to Internet Explorer 8 or newer for a better experience.Close Icon

Live Chat Icon For mobile