mxdeluxe
mxdeluxe

Reputation: 43

Make FloatingWindow modal

I am using the AvalonDock control to show my views as tabs. In some cases I want to open a new window instead. At the moment, I'm handling that in the LayoutInitializer:

public void AfterInsertDocument(LayoutRoot layout, LayoutDocument anchorableShown)
{
    if (anchorableShown.Content != null && anchorableShown.Content is ViewModelBase)
    {
        var viewModel = ((ViewModelBase)anchorableShown.Content);
        if (viewModel.Type == ViewModelBase.ViewType.Popup)
        {
            anchorableShown.FloatingWidth = viewModel.PopupWidth;
            anchorableShown.FloatingHeight = viewModel.PopupHeight;
            anchorableShown.FloatingTop = viewModel.PopupTop;
            anchorableShown.FloatingLeft = viewModel.PopupLeft;

            anchorableShown.Float();
        }
    }        
}

That works fine. But I want to have this new floated window as a modal window. And it must not be dockable. I don't know where I can handle that.

Upvotes: 1

Views: 493

Answers (1)

mxdeluxe
mxdeluxe

Reputation: 43

The best way - as @stijn already answered - is to create a seperate window.

Here is my XAML definition:

<Window ... >
    <Window.Resources>
        <DataTemplate  DataType="{x:Type local:FirstViewModel}">
            <local:FirstView />
        </DataTemplate>

        <DataTemplate DataType="{x:Type local:SecondViewModel}">
            <local:SecondView />
        </DataTemplate>

    </Window.Resources>

    <DockPanel LastChildFill="True" Name="mainPanel" >
        <ContentPresenter  Content="{Binding}">
        </ContentPresenter>
    </DockPanel>
</Window>

Foreach ViewModel/View assignment I use this DataTemplate block.

In my WindowManager implementation, I create a new window:

private System.Windows.Window CreateWindow(ViewModelBase viewModel)
{
    var window = new PopupWindow();
    window.DataContext = viewModel;

    return window;
}

... and show it as modal window:

public void ShowWindow(ViewModelBase viewModel)
{
    var window = CreateWindow(viewModel);
    window.ShowDialog();
}

Upvotes: 2

Related Questions