Your Privacy Matters: We use our own and third-party cookies to improve your experience on our website. By continuing to use the website we understand that you accept their use. Cookie Policy
85
How can I select or activate a ContentPane without causing a Window.Activate
posted

We have a situation where we need to display a particular ContentPane (in a TabGroup or DocumentContentHost) without causing the application to steal the focus. We are currently using latest NetAdvantage WPF v9.2.

Unfortunately, ContentPane.Activate() internally calls Window.Activate() on the Window that contains the ContentPane, this causes the application to get focus if it does not already have it.

Is there any way to make a ContentPane visible without causing the application to steal focus?

Below is a simple test that shows the problem. When this window is running the active pane is changed every second and each time the active pane changes the application gets focus (try clicking on another application while it is running).

<UserControl x:Class="Tests.ContentPaneActivateView"
             xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
             xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
             xmlns:dm="clr-namespace:Infragistics.Windows.DockManager;assembly=Infragistics3.Wpf.DockManager.v9.2">
    <Grid>
        <dm:XamDockManager>
            <dm:SplitPane>
                <dm:TabGroupPane Name="TabGroup">
                    <dm:ContentPane Header="Pane 1">
                        <RichTextBox/>
                    </dm:ContentPane>
                    <dm:ContentPane Header="Pane 2">
                        <RichTextBox/>
                    </dm:ContentPane>
                    <dm:ContentPane Header="Pane 3">
                        <RichTextBox/>
                    </dm:ContentPane>
                    <dm:ContentPane Header="Pane 4">
                        <RichTextBox/>
                    </dm:ContentPane>
                </dm:TabGroupPane>
            </dm:SplitPane>
        </dm:XamDockManager>
    </Grid>
</UserControl>

namespace Tests
{
    [TestFixture]
    public class ContentPaneActivateTest
    {
        [Test]
        public void ShouldActivateContentPane()
        {
            var view = new ContentPaneActivateView();
            var panes = view.TabGroup.Items;

            int index = 0;
            var timer = new DispatcherTimer(TimeSpan.FromSeconds(1),
                                            DispatcherPriority.Background,
                                            (o, e) => ((ContentPane) panes[index++ % panes.Count]).Activate(),
                                            Dispatcher.CurrentDispatcher);
            timer.Start();

            new Window { Content = view }.ShowDialog();
        }       
    }
}

Parents Reply Children