I like the way Prism 5.0 Interactivity works, but it can just open UserControls
and Panels
and such inside a Window
it creates. So since it cannot place a Window
inside another Window
you can't pass a view for it that has Window
as the root element.
The problem is, when it places my UserControl
inside the Window
it created, the Window
has not a MinWidth
or MinHeight
or a ResizeMode="NoResize"
option to be selected, thus, the user interface becomes horrible.
Are there any ways to control the Window
's properties so I can customize it as I want?
PS: It amazes me how a big and important company as Microsoft can release a Best Practices library with stuff missing like that.
As requested, here comes a code example:
In order to open a view in a new Window
in Prism, you have to add this to the current view (the view that's going to invoke the creation of a new Window
in it's ViewModel
):
<prism:InteractionRequestTrigger SourceObject="{Binding ItemSelectionRequest, Mode=OneWay}">
<!-- This PopupWindowAction has a custom view defined. When this action is executed the view will be shown inside a new window -->
<!-- Take into account that the view and its view model are created only once and will be reused each time the action is executed -->
<prism:PopupWindowAction>
<prism:PopupWindowAction.WindowContent>
<views:ItemSelectionView />
</prism:PopupWindowAction.WindowContent>
</prism:PopupWindowAction>
</prism:InteractionRequestTrigger>
If you change this ItemSelectionView
from a UserControl
to a Window
, you will get this exception:
Since basically Prism will try to place a Window
inside a Window
when it creates a new Window
and a new ItemSelectionView
and tries to put one inside the other...and Windows
are suppose to be the root always, but in this case Window
ItemSelectionView
will be placed as a child of a new Window
.
More information about how this works, please go to the link I posted.
For now I am using code behind to tweak the window, I check if this UserControl
is the root of the Window, and only in that case I teak the Window's
settings (this isn't ideal, but still isn't a violation of MVVM):
private void OnLoaded(object sender, System.Windows.RoutedEventArgs e)
{
Window parentWindow = Window.GetWindow(this);
if (parentWindow != null && parentWindow.Content == this)
{
parentWindow.ResizeMode = ResizeMode.NoResize;
parentWindow.SizeToContent = SizeToContent.Height;
parentWindow.MinHeight = this.MinHeight;
parentWindow.MinWidth = this.MinWidth;
}
}
There is a pretty simple solution.
Since the
PopupWindowAction
creates the wrapper windows as instances of theWindow
class, you can apply a default style to the typeWindow
in your app.xaml.