Christian Feininger

Hello,

I have a grid which is hooked up in a window. The grid contains some buttons. I want to force the grid that when i resize my window that you can only resize to a minimum so that all content are still visible. You shouldn't be able to resize the window so small that all content gets away

How do I do that

cheers

chris

Code Snippet

<Window x:Class="WMSClientUserControlTest.Window1"

xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"

xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"

xmlns:WMSClientUserControls="clr-Title="Window1">

<Grid>

<Grid.ColumnDefinitions>

<ColumnDefinition/>

</Grid.ColumnDefinitions>

<Grid.RowDefinitions>

<RowDefinition/>

<RowDefinition/>

</Grid.RowDefinitions>

<Button Height="23" Grid.Column="0" Grid.Row="0" Name="button1" Width="112" Click="button1_Click">Add Error Message</Button>

<TextBox Height="21" Grid.Column="0" Grid.Row="1" Name="messageTextBox" Width="120" />

</Grid>

</Window>



Re: Windows Presentation Foundation (WPF) Grid Resizing

lee d

try setting the MinHeight and MinWidth properties on the window






Re: Windows Presentation Foundation (WPF) Grid Resizing

Christian Feininger

yeah i know that. but than i have to figure out manual how huge the window is at the beginning. Is there no option which force the window or the nested grid no to resize small than the content





Re: Windows Presentation Foundation (WPF) Grid Resizing

lee d

you can try setting the SizeToContent property of the window to "WidthAndHeight"






Re: Windows Presentation Foundation (WPF) Grid Resizing

Christian Feininger

this just forces the window to show up in correct size but doen't force it to resize it smaller.

any other suggestions or is it just not possible in wpf





Re: Windows Presentation Foundation (WPF) Grid Resizing

Christian Feininger





Re: Windows Presentation Foundation (WPF) Grid Resizing

Matt Hohn [MSFT]

You could use ResizeMode="NoResize". That you would not be able to resize the window. Or i would recomend the Min/Max Height/WIdth properties on the window.






Re: Windows Presentation Foundation (WPF) Grid Resizing

Matt Hohn [MSFT]

Or... you could try something like this

Code Snippet

<Window x:Class="sample.Window1"

xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"

xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"

Title="Window1"

Height="500" Width="500"

MinWidth="{Binding ElementName=grid, Path=ActualWidth}"

MinHeight="{Binding ElementName=grid, Path=ActualHeight}">

<Grid Background="orange" Height="250" Width="250" Name="grid">

...

</Grid>

</Window>






Re: Windows Presentation Foundation (WPF) Grid Resizing

Christian Feininger

Thanks,

I see there is no option which really does what I want to. I did it with MinWidth and MinHeight.

Thanks for help





Re: Windows Presentation Foundation (WPF) Grid Resizing

Matt Hohn [MSFT]

I am sorry if I misunderstood your scenario. If this is a layout scenario that is not possible I would like to know what it is, so I hope you don¡¯t mind my asking for more information.

Correct me if I am wrong with this scenario..

You want the Grid to size to its content

And you want to be able to resize the Window, but it should never be smaller than the Grid






Re: Windows Presentation Foundation (WPF) Grid Resizing

Christian Feininger

Yeah that's nearly the sceanrio.

I want that the window starts with the content which is necessary to show all content of the grid. I also want that you are able to resize the window (make it bigger). But I don't want that you are able to resize the window so that some of the content (e.g. buttons, textbox whatever) disappear because of a resizing action from a user.

Is that possible





Re: Windows Presentation Foundation (WPF) Grid Resizing

Marlon Grech


you can use the Loaded event of the window and resize the window in there....

void Loaded...
{
this.Height=myGrid.Height;
this.Width = myGrid.Width;
}





Re: Windows Presentation Foundation (WPF) Grid Resizing

Christian Feininger

To resize the window at the beginning your soloution works but this still doesn't force that you can't make it smaller than the content at the beginning.





Re: Windows Presentation Foundation (WPF) Grid Resizing

Marlon Grech


you can use the minheight andd min width for that feature...