【问题标题】:initial size of element wpf元素 wpf 的初始大小
【发布时间】:2013-02-06 08:37:16
【问题描述】:

我有这个标记的窗口

<Window x:Class="TestCloseWindow.MainWindow"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        Title="MainWindow">

        <Button Command="ApplicationCommands.Close">Foo</Button>

</Window>

我想按钮 MinWidth 和 MinHeight 100 并且 MaxHeight 和 MinHeight 等于 500

并且喜欢将窗口大小设置为内容,所以我制作了这个

<Window x:Class="TestCloseWindow.MainWindow"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        Title="MainWindow" SizeToContent="WidthAndHeight" >

        <Button MaxHeight="500" MaxWidth="500" MinHeight="100" MinWidth="100" Command="ApplicationCommands.Close">Foo</Button>

</Window>

我想将按钮的初始大小设置为 200 x 200 不在窗口中写宽度和高度

如果我在按钮中写 Width="200" Height="200",按钮变得不可调整大小。

如何设置初始控件的大小?

【问题讨论】:

  • 所以你想让元素知道你想要它的大小而不告诉它?
  • @sa_ddam213 我想以某种方式告诉元素的初始大小。如果我把 Width="200" Height="200" 元素变得无法调整大小

标签: wpf


【解决方案1】:

我不确定您到底想要完成什么,但看看这是否符合您的要求。我正在使用 ViewBox 在调整窗口大小时拉伸内容,并在窗口中设置约束。请注意,窗口大小与窗口客户区大小不同。

<Window x:Class="WpfApplication1.MainWindow"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        Title="MainWindow"  MaxHeight="500" MaxWidth="500" 
        MinWidth="100" MinHeight="100" 
        Width="200" Height="200">
    <Viewbox StretchDirection="Both" Stretch="Fill">
        <Button >Hello</Button>
    </Viewbox>

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2022-06-10
    • 2011-07-12
    • 1970-01-01
    • 1970-01-01
    • 2011-09-08
    • 1970-01-01
    • 2012-02-12
    • 1970-01-01
    相关资源
    最近更新 更多