2
votes

I have window with this markup

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

I'd like to button have MinWidth and MinHeight 100 and MaxHeight and MinHeight equals to 500

And like size window to content so I make this

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

And I'd like to set initial size of button 200 x 200 without writing Width and Height in window

If I write Width="200" Height="200" in button, button becomes unresizable.

How can I set initial size of control?

1
so you want the Element to somehow know what size you want it to be without telling it? - sa_ddam213
@sa_ddam213 I want somehow to tell initial size of element. If I put Width="200" Height="200" element becomes unresizable - takayoshi

1 Answers

0
votes

I am not sure exactly what you are trying to accomplish, but see if this does what you are wanting. I am using a ViewBox to stretch the Contents when the Window is resized, and setting the contraints in the Window. Be aware that Window Size is different than Window Client Area size.

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