Anton
Anton

Reputation: 339

Resizable dialog window in WPF

I use MetroWindow class from Mahapps to show dialog window of some kind. My idea was to create auto resizable window, to fit it's content size

<controls:MetroWindow 
    ...
    DataContext="{Binding DialogVM, Source={StaticResource ViewModelLocator}}"
    Title="{Binding WindowHeader}"
    WindowTitleBrush="{StaticResource MainStyleTitleBrush}"
    Background="{StaticResource MainStyleBackgroundBrush}"
    wpfExtensions:SizeObserver.Observe="True"
    wpfExtensions:SizeObserver.ObservedWidth="{Binding xHeight, Mode=OneWayToSource}"
    wpfExtensions:SizeObserver.ObservedHeight="{Binding xWidth, Mode=OneWay}"
    MaxWidth="1110" MaxHeight="1080"
    MinWidth="450" MinHeight="600"
    ShowMinButton="False"
    ShowMaxRestoreButton="False"
    BorderThickness="1"
    BorderBrush="{StaticResource MainStyleBorderBrush}"
    SizeToContent="Width"
    WindowStartupLocation="CenterScreen">
    <Grid>
      <ContentPresenter  Content="{Binding VM}"/>
    </Grid>  
</controls:MetroWindo>     

but I have two issues First one: My window is affected to user actions (Mouse double click on title, drag window to left or right screen edge, and so on), and I want it to be frozen, but resizable. Second one: when I reshow the same window again (without recreating it, but with new content which can have new visible size) it show's on it's last position.

How can I solve this problems without code-behind WindowSizeChanged event catching?

Upvotes: 1

Views: 1887

Answers (1)

GCamel
GCamel

Reputation: 622

put ResizeMode="NoResize" and SizeToContent="WidthAndHeight"

Upvotes: 2

Related Questions