【问题标题】:MinWidth, MaxWidth, MinHeight, MaxHeight don't have effect for <UserControl>MinWidth、MaxWidth、MinHeight、MaxHeight 对 <UserControl> 无效
【发布时间】:2015-10-10 13:11:27
【问题描述】:

我正在学习使用 Caliburn Micro 框架创建 WPF 应用程序。

按照主页上的教程:Basic Configuration,我删除了默认生成的&lt;Window&gt; xaml,取而代之的是&lt;UserControl&gt; xaml,并通过我的AppBoostrapper 引导它。

这是 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>

问题是我想为我的应用程序设置MinWidth, MaxWidth, MinHeight, MaxHeight,但似乎MainWindow.xaml 中的那些配置不起作用。

这是两个屏幕截图,窗口仍然可以在定义的范围之外调整大小:

我哪里错了?

【问题讨论】:

  • 嘿!我现在也有同样的问题,你现在知道怎么解决了吗?
  • 不 :(。我找不到解决方案。
  • 我已经解决了这个问题,但是我的代码有问题。我们处理了 WinAPI 事件 (WindowProc) - 在这种情况下,我们的窗口甚至没有使用 MinWidth 和 MaxWidth ;)

标签: c# wpf xaml user-controls caliburn.micro


【解决方案1】:

UserControl 的宽度和高度属性由包含该控件的容器设置。 IE。在设计时使用的 DesignWidth 和 DesignHeigth 在 UserControl 中设置,但在运行时它使用容器设置的值。

我在 Caliburn Micro 方面没有经验,但您似乎可以在引导程序中定义设计属性:

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

   DisplayRootViewFor<ViewModel>(settings);

【讨论】:

    猜你喜欢
    • 2014-09-29
    • 1970-01-01
    • 2021-11-26
    • 1970-01-01
    • 2018-11-06
    • 2020-03-30
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多