简体   繁体   中英

MinWidth, MaxWidth, MinHeight, MaxHeight don't have effect for <UserControl>

I'm learning to create WPF application with Caliburn Micro framework.

Following the tutorial on the homepage: Basic Configuration , I removed the default generated <Window> xaml, instead, I have <UserControl> xaml and bootstrap it via my AppBoostrapper .

Here is the MainView.xaml:

<UserControl x:Class="SmartRenamer.Views.MainView"
             xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
             xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
             xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 
             xmlns:d="http://schemas.microsoft.com/expression/blend/2008" 
             mc:Ignorable="d" 
             d:DesignHeight="300" d:DesignWidth="300"
             MinHeight="300"
             MinWidth="300"
             MaxHeight="500"
             MaxWidth="1000">
    <Grid>
        <Grid.RowDefinitions>
            <RowDefinition Height="Auto" />
            <RowDefinition Height="*" />
        </Grid.RowDefinitions>
        <Menu IsMainMenu="True" Grid.Row="0">
            <MenuItem Header="_File">
                <MenuItem Header="_Open Folder..." x:Name="OpenFolder"></MenuItem>
            </MenuItem>
            <MenuItem Header="_About" />
        </Menu>
        <ScrollViewer HorizontalScrollBarVisibility="Visible" Grid.Row="1" MaxHeight="500" MaxWidth="1000">
            <StackPanel>
                <DataGrid x:Name="FilesList">

                </DataGrid>
            </StackPanel>
        </ScrollViewer>
    </Grid>
</UserControl>

The problem is I want to set the MinWidth, MaxWidth, MinHeight, MaxHeight for my application, but it seems that those configuration in the MainWindow.xaml isn't working.

Here is the two screenshots, where the window is still can be re-sized out of the defined range:

非常小的窗户很大的窗户 What am I wrong here?

The width and height properties of an UserControl is set by the container that holds that control. Ie the DesignWidth and DesignHeigth that are used in the design-time are set in the UserControl but in runtime it uses the values set by the container.

I am not experienced in Caliburn Micro but it seems like you can define the design properties in the bootstrapper:

   var settings = new Dictionary<string, object>
   {
       { "Height" , 300},
       { "Width"  , 300},
   };

   DisplayRootViewFor<ViewModel>(settings);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM