HStewart
HStewart

Reputation: 31

Desire specific size of Visual Studio 2019 Extension ToolWindow ( WPF UserControl )

I am looking to get a fix size windows because of content that I am showing. I am struggling because when the extension is run the size of windows is crop to a fix size. The simple example is just modified the default and try to make it 800x600 window. Once the window is up on screen, you can manual adjust and next time it will be fine but I wish to make sure the default is correct.

I seen other questions about like not having fix size and such and nothing seems to work. I understand if user changes the size smaller than it will be that may - but I would like default size to be bigger

<UserControl x:Class="VSIXProject1.ToolWindow1Control"
         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"
         xmlns:vsshell="clr-namespace:Microsoft.VisualStudio.Shell;assembly=Microsoft.VisualStudio.Shell.15.0"
         Background="{DynamicResource {x:Static vsshell:VsBrushes.WindowKey}}"
         Foreground="{DynamicResource {x:Static vsshell:VsBrushes.WindowTextKey}}"
         mc:Ignorable="d"
         d:DesignHeight="600" d:DesignWidth="800"
         Name="MyToolWindow">
<Grid MinWidth="800" MinHeight="600">
    <StackPanel Orientation="Vertical" Width="800" Height="600">
        <TextBlock Margin="10" HorizontalAlignment="Center">ToolWindow1</TextBlock>
        <Button Content="Click me!" Click="button1_Click" Width="120" Height="80" Name="button1"/>
    </StackPanel>
</Grid>

Source Image Problem Image

I try following code in Package class as recommended

 [ProvideToolWindow(typeof(ToolWindow1),
                       Width =800,
                       Height =600,
                       Style = Microsoft.VisualStudio.Shell.VsDockStyle.AlwaysFloat)]

Upvotes: 0

Views: 605

Answers (2)

Ed Dore
Ed Dore

Reputation: 2109

You can stipulate the initial size of a toolwindow by setting the Width and Height properties, via the ProvideToolWindowAttribute, used to register your toolwindow. Toolwindows are "sticky", with the position, size, dockstate etc being persisted with your other window layout options. Meaning, once the user resizes/docs/floats the toolwindow, it's state gets saved. But you can readily reset it back to the default, using the Windows | Reset Window Layout menu command.

Sincerely,

Upvotes: 1

Stefano Cavion
Stefano Cavion

Reputation: 741

Hi you can set the Window size in this way

<UserControl x:Class="VSIXProject1.ToolWindow1Control"
     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"
     xmlns:vsshell="clr-namespace:Microsoft.VisualStudio.Shell;assembly=Microsoft.VisualStudio.Shell.15.0"
     Background="{DynamicResource {x:Static vsshell:VsBrushes.WindowKey}}"
     Foreground="{DynamicResource {x:Static vsshell:VsBrushes.WindowTextKey}}"
     MinWidth = "800"
     MinHeight = "600"
     mc:Ignorable="d"
     d:DesignHeight="600" d:DesignWidth="800"
     Name="MyToolWindow">

Set the MinWidth and MinHeight will ensure that window will never go under that dimension

Upvotes: 0

Related Questions