提问者:小点点

Visual Studio 2019扩展工具窗口所需的特定大小(WPF UserControl)


我希望得到一个固定大小的窗口,因为我正在显示的内容。 我很挣扎,因为当扩展运行时,窗口的大小是裁剪到一个固定的大小。 这个简单的例子只是修改了默认值,并尝试使其成为800x600窗口。 一旦窗口是在屏幕上,你可以手动调整,下次它将是好的,但我希望确保默认是正确的。

我看到了其他的问题,像没有固定的大小和诸如此类,似乎没有工作。 我理解如果用户改变的大小比它可能会更小,但我希望默认大小更大

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

源映像问题映像


共1个答案

匿名用户

嗨,你可以用这种方式设置窗口大小

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

设置MINWIDTHMINHEIGH将确保窗口永远不会在该维度下运行