DocumentWindow IsVisibleChanged fires multiple times

Docking/MDI for WPF Forum

Posted 13 years ago by Mick
Version: 11.1.0545
Avatar
Sample:

<Window
    x:Class="DocumentWindowIsVisibleChanged.MainWindow"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:docking="http://schemas.actiprosoftware.com/winfx/xaml/docking"
    Title="MainWindow" Height="350" Width="525">
    <Grid>
        <Grid.RowDefinitions>
            <RowDefinition />
            <RowDefinition Height="auto" />
        </Grid.RowDefinitions>
        <docking:DockSite Name="docksite">
            <docking:Workspace>
                <docking:TabbedMdiHost>
                    <docking:TabbedMdiContainer />
                </docking:TabbedMdiHost>
            </docking:Workspace>
        </docking:DockSite>
        <Button Grid.Row="1" Content="Create new window and dock" Click="Button_Click" />
    </Grid>
</Window>

using System;
using System.Windows;
using ActiproSoftware.Windows.Controls.Docking;
using System.Collections.Generic;
using System.Windows.Controls;

namespace DocumentWindowIsVisibleChanged
{
    public partial class MainWindow : Window
    {
        int windowNumber = 0;
        private static string calls = string.Empty;
        public MainWindow() { InitializeComponent(); }

        private void Button_Click(object sender, RoutedEventArgs e)
        {
            calls = string.Empty;
            DocumentWindow dw = new DocumentWindow(docksite, "window" + windowNumber, "window" + windowNumber, null, null) { Tag = "window" + windowNumber };
            dw.IsVisibleChanged += dw_IsVisibleChanged;

            dw.Activate();
            MessageBox.Show(calls, "DocumentWindow.IsVisibleChanged call History");

            windowNumber++;
        }

        private void dw_IsVisibleChanged(object sender, DependencyPropertyChangedEventArgs e)
        {
            calls += string.Format("{0}: OldValue={1}, NewValue={2}{3}", (string)((DocumentWindow)sender).Tag, e.OldValue, e.NewValue, Environment.NewLine);
        }
    }
}
When a window is created, IsVisible is being set to true, then to false, and then back to true. When I add a new window, the prior window sets its visibility to false, and then sets it to true.

If I have logic that fires when the window becomes visible, it may fire twice under this scenario.

If I'm looking to find when a window is made visible, is there a different event I should be watching or an easy way to work around this?

Thank you,
Mick

Comments (1)

Posted 13 years ago by Actipro Software Support - Cleveland, OH, USA
Avatar
Hi Mick,

Sorry for the delay, I didn't receive a notification of your post.

You would probably be better off using DockSite.WindowOpened/WindowClosed instead. The DocumentWindow is only responsible for rendering it's tab, not it's content. So the DocumentWindow may still be visible, while not selected. In addition, when floated there is no tab for DocumentWindows, so technically it would not be visible.

If there is something on your content that needs to know when it's visible, then you could attach to it's IsVisibleChanged event instead.


Actipro Software Support

The latest build of this product (v24.1.2) was released 2 days ago, which was after the last post in this thread.

Add Comment

Please log in to a validated account to post comments.