I'm writing an application in WPF using the MVVM pattern. In my application I've got an IPopupWindowService
which I use to create a popup dialog window.
So to show a ViewModel in a popup window you'd do something like this:
var container = ServiceLocator.Current.GetInstance<IUnityContainer>();
var popupService = container.Resolve<IPopupWindowService>();
var myViewModel = container.Resolve<IMyViewModel>();
popupService.Show((ViewModelBase)myViewModel);
This is all well and good. What I want to do is be able to set the MinHeight
and MinWidth
on the View
bound to myViewModel
and have the popup window use those settings so that a user cannot make the window smaller than its contents will allow. At the moment when the user shrinks the window the contents stops resizing but the window doesn't.
EDIT:
I map my Views to my ViewModels in ResourceDictionarys like so:
<DataTemplate DataType="{x:Type ViewModels:MyViewModel}">
<Views:MyView />
</DataTemplate>
And my popup view looks like this:
<Window x:Class="TheCompany.Cubit.Shell.Views.PopupWindowView"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
SizeToContent="WidthAndHeight"
WindowStartupLocation="CenterOwner">
<DockPanel x:Name="panelContent">
<StackPanel HorizontalAlignment="Right" DockPanel.Dock="Bottom" Orientation="Horizontal" Visibility="{Binding RelativeSource={RelativeSource AncestorType=Window},Path=ButtonPanelVisibility}">
<Button Width="75" IsDefault="True" x:Uid="ViewDialog_AcceptButton" Click="OnAcceptButtonClick" Margin="4">OK</Button>
<Button Width="75" IsCancel="True" x:Uid="ViewDialog_CancelButton" Click="OnCancelButtonClick" Margin="0,4,4,4">Cancel</Button>
</StackPanel>
<ContentPresenter Content="{Binding}" />
</DockPanel>